Hprose is a cross-language RPC. This project is Hprose for Golang.



Hprose 3.0 for Golang

Join the chat at https://gitter.im/hprose/hprose-golang Build Status GoDoc Go Report Card codebeat badge Coverage Status License


Hprose is a High Performance Remote Object Service Engine.

It is a modern, lightweight, cross-language, cross-platform, object-oriented, high performance, remote dynamic communication middleware. It is not only easy to use, but powerful. You just need a little time to learn, then you can use it to easily construct cross language cross platform distributed application system.

Hprose supports many programming languages, for example:

  • AAuto Quicker
  • ActionScript
  • ASP
  • C++
  • Dart
  • Delphi/Free Pascal
  • dotNET(C#, Visual Basic...)
  • Golang
  • Java
  • JavaScript
  • Node.js
  • Objective-C
  • Perl
  • PHP
  • Python
  • Ruby
  • ...

Through Hprose, You can conveniently and efficiently intercommunicate between those programming languages.

This project is the implementation of Hprose 3.0 for Golang.

  • jsonrpc_client_filter 处理 map[string]interface{} 类型参数时的问题

    jsonrpc_client_filter 处理 map[string]interface{} 类型参数时的问题

    Hi, 我有一个如下式样的方法.

    type stub struct {
        IndexDoc  func(indexName, docId string, doc map[string]interface{}) error

    在对 client 设置了 NewJSONRPCClientFilter("2.0") 之后, 调用始终报 no Hprose RPC request.
    而不设置 json filter 的时候, 是可以正常调用.

    我进行了一些调试, 发现处理过程中, https://github.com/hprose/hprose-go/blob/master/hprose/jsonrpc_client_filter.go#L89 这里实际会报错: json: unsupported type: map[interface {}]interface {}, 导致 data 为空.

    由此处向上回溯, 产生这个结果的相关代码如下: https://github.com/hprose/hprose-go/blob/master/hprose/jsonrpc_client_filter.go#L81


    我尝试了 byref 的方式, 但是在向服务圈发起请求之前就出现了一个 runtime error: index out of range 我还没有确认问题的原因.

    opened by dtynn 10
  • 在golang做server,用js调用遇到跨域问题怎么解决?


    先贴出主要代码 //server type event struct{}

    func (e event) OnSendHeader(ctx rpc.HTTPContext) { ctx.Response.Header().Set("Access-Control-Allow-Origin", ""); ctx.Response.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE"); ctx.Response.Header().Set("Access-Control-Allow-Headers","Authorization") }

    func Server() { service := rpc.NewHTTPService() handler := struct { User user }{} service.Event = event{} ……

    //client …… export function UserGet() { return (dispatch, getState) => { const cluster = localStorage.getItem('cluster'); const token = localStorage.getItem('token'); dispatch(userGetRequest()); if (!cluster || !token) { dispatch(userGetFailure('No authorization')); return; } const client = Client.create(${cluster}/api, { User: ['Get'] });

    client.setHeader('Authorization', `Bearer ${token}`);
    client.User.Get(null, (resp) => {
      if (resp.success) {
      } else {
    }, (resp, err) => {
      dispatch(userGetFailure('Server error'));
      console.log('【Hprose】User.Get Error:', resp, err);

    }; } ……

    版本: server:golang1.12 hprose 2.0 client :hprosejs 2.0.33

        我用firefox调用时提示 missing token ‘authorization’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel),

    用chrome调用时提示 Access to XMLHttpRequest at '' from origin '' has been blocked by CORS policy: Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response. 请问问题到底出现在哪?我是不是哪里写错了?貌似onSendHeader没有起到作用,求解决。

    opened by shioyim 7
  • client.Subscribe 触发server OnSubscribe事件的时间要比client.Subscribe之后的远程调用晚。

    client.Subscribe 触发server OnSubscribe事件的时间要比client.Subscribe之后的远程调用晚。

    本来client.Subscribe 之后调用其他client.remotecallXXXX,本来期望这个过程是同步的,即client.Subscribe返回后调用client.remotecallXXXX。在client.remotecallXXXX时触发服务器的 OnSubscribe事件,做好相应处理,才能保证之后的client.remotecallXXXX正确调用。但目前这点无法保证。

    opened by OliverZou 6
  • 请问如何使用返回机构体,然后远程调用结构体方法


    服务端代码 ` package main

    import ( "net/http"

    rpc "github.com/hprose/hprose-golang/rpc/websocket"


    type Hello struct { Name string }

    func NewHello(name string) Hello { return Hello{Name: name} }

    func (this Hello) Hello(speak string) string { return "Hello " + this.Name + speak + "!" }

    func main() { service := rpc.NewWebSocketService() service.AddFunction("newhello", NewHello) http.ListenAndServe(":8080", service) } ` 请问客户端如何使用初始化结构后Hello方法,

    opened by fromiuan 6
  • 参数传输性能较低


    // hps_001 project main.go package main

    import ( "github.com/hprose/hprose-go" )

    func WriteParas(paras []int) int { return 1 }

    func main() { service := hprose.NewTcpServer("tcp://") service.AddFunction("WriteParas", WriteParas) service.Start() }

    // hpc_001 project main.go package main

    import ( "fmt" "github.com/hprose/hprose-go" "time" )

    type Stub struct { WriteParas func([]int) int }

    func main() { client := hprose.NewTcpClient("tcp://")

    var ro *Stub
    paras := make([]int, 10000000)
    for {
        startTm := time.Now().UnixNano()
        endTm := time.Now().UnixNano()
        fmt.Println("use time ", float64(endTm-startTm)/1000000.0, " ms")


    在windows 7 64bit, go 1.5.1,硬件配置thinkpad t430s上运行,每次调用要 use time 555.0317 ms use time 535.0306 ms use time 546.0313 ms use time 541.0309 ms use time 547.0313 ms 处理效率较低

    opened by yuyi98 6
  • Why can work well without ClassManager.Register when use custom struct

    Why can work well without ClassManager.Register when use custom struct

    // hps_001 project main.go package main

    import ( "github.com/hprose/hprose-go" "net/http" _ "reflect" )

    type FloatPara struct { Id int32 Tag string Desc string Tm int32 }

    type FloatData struct { Id int32 Para []FloatPara }

    func getMeasList() FloatData { return FloatData{22, []FloatPara{FloatPara{11, "float001", "desc_float001", 11111}, FloatPara{22, "float002", "desc_float002", 22222}}} }

    func main() { //hprose.ClassManager.Register(reflect.TypeOf(FloatPara{}), "Para") //hprose.ClassManager.Register(reflect.TypeOf(FloatData{}), "Data")

    service := hprose.NewHttpService()
    service.AddFunction("getMeasList", getMeasList)
    http.ListenAndServe(":8080", service)


    // hpc_001 project main.go package main

    import ( "fmt" "github.com/hprose/hprose-go" _"reflect" )

    type FloatPara struct { Id int8 Tag string Desc string Tm int16 }

    type FloatData struct { Id int32 Para []FloatPara }

    type Stub struct { GetMeasList func() FloatData }

    func main() { //hprose.ClassManager.Register(reflect.TypeOf(FloatPara{}), "FloatPara") //hprose.ClassManager.Register(reflect.TypeOf(FloatData{}), "FloatData") client := hprose.NewClient("")

    var ro *Stub
    aa := ro.GetMeasList()


    it can work well, why?

    opened by yuyi98 6
  • tcp服务是单线程没有开协程吗,不能并行处理多个请求?



    global.LogId = strconv.FormatInt(rand.Int63(),10)
    pUser, _ := model.SpecialUsers.UserList(where, AWhere, page, pageSize)

    5577006791947779410 5577006791947779410 8674665223082153551 8674665223082153551 6129484611666145821


    opened by dongbufan 5
  • Go客户端的NewClient函数是否可以先建立连接,返回连接信息?


    opened by yuyi98 5
  • 如何支持可变的方法返回值?



    type Order struct {
    	Id    int64  `json:"id"`
    type HappyRsp struct {
         Status int         `json:"status"`,
         Data Order `json: "order"`
    type UnHappyRsp struct {
    	Status int           `json:"status"`
            // 这里不能是ErrorMessage, 必须保留下划线在Error_Message名字里面,否则方法返回空值。
    	Error_Message    string           `json:"error_message"` 
    type SampleService struct {
    	GetOrder func(*map[string]string) (HappyRsp, error) `name:"getOrder"`


    1. 我现在的服务端GetOrder方法可能会返回UnHappyRsp,而不是抛出error。在不改动服务端的情况下,客户端方法如何适配服务的的多种返回类型?
    2. UnHappyRsp里面的Error_Message名字,必须保留下划线,不能按照Golang风格重命名为ErrorMessage,不知道这个是不是bug?


    opened by adamllv 4
  • 如何在invokeHandler中获取 service 名称?

    如何在invokeHandler中获取 service 名称?

    server.AddInstanceMethods(&serviceA) server.AddInstanceMethods(&serviceB) server.AddInvokeHandler(InvokeHandler)

    如上,在InvokeHandler中 func InvokeHandler(name string, args []reflect.Value, context rpc.Context, next rpc.NextInvokeHandler) (results []reflect.Value, err error) name是调用的serviceA或serviceB中的方法名,如何获取这个name是属于哪个 service的调用?

    opened by ideamean 4
  • 传入多个tcp地址建立客户端,请求的时候没有负载均衡


    测试 请求全部集中在第一个服务器tcp://或者第二个tcp://,没有负载均衡

    client := rpc.NewClient("tcp://","tcp://") var stub *Stub client.UseService(&stub)

    for i:=0; i<8 ; i++ {
    opened by zhuxiujia 4
Hprose is a High Performance Remote Object Service Engine.
Simple, fast and scalable golang rpc library for high load

gorpc Simple, fast and scalable golang RPC library for high load and microservices. Gorpc provides the following features useful for highly loaded pro

Aliaksandr Valialkin 664 Nov 17, 2022
The jsonrpc package helps implement of JSON-RPC 2.0

jsonrpc About Simple, Poetic, Pithy. No reflect package. But reflect package is used only when invoke the debug handler. Support GAE/Go Standard Envir

Osamu TONOMORI 172 Nov 20, 2022
A simple go implementation of json rpc 2.0 client over http

JSON-RPC 2.0 Client for golang A go implementation of an rpc client using json as data format over http. The implementation is based on the JSON-RPC 2

Alexander Gehres 252 Nov 21, 2022
A Go library for master-less peer-to-peer autodiscovery and RPC between HTTP services

sleuth sleuth is a Go library that provides master-less peer-to-peer autodiscovery and RPC between HTTP services that reside on the same network. It w

null 360 Nov 17, 2022
Distributed Lab 2: RPC in Go

Distributed Lab 2: RPC in Go Using the lab sheet There are two ways to use the lab sheet, you can either: create a new repo from this template - this

null 0 Oct 18, 2021
Cross-platform grid-based user interface framework.

Gruid The gruid module provides packages for easily building grid-based applications in Go. The library abstracts rendering and input for different pl

null 69 Nov 23, 2022
Lockgate is a cross-platform locking library for Go with distributed locks using Kubernetes or lockgate HTTP lock server as well as the OS file locks support.

Lockgate Lockgate is a locking library for Go. Classical interface: 2 types of locks: shared and exclusive; 2 modes of locking: blocking and non-block

werf 230 Oct 26, 2022
Golang client library for adding support for interacting and monitoring Celery workers, tasks and events.

Celeriac Golang client library for adding support for interacting and monitoring Celery workers and tasks. It provides functionality to place tasks on

Stefan von Cavallar 73 Oct 28, 2022
Consistent hashing with bounded loads in Golang

consistent This library provides a consistent hashing function which simultaneously achieves both uniformity and consistency. For detailed information

Burak Sezer 535 Nov 28, 2022
Compute cluster (HPC) job submission library for Go (#golang) based on the open DRMAA standard.

go-drmaa This is a job submission library for Go (#golang) which is compatible to the DRMAA standard. The Go library is a wrapper around the DRMAA C l

Daniel Gruber 43 Nov 17, 2022
AppsFlyer 500 Dec 1, 2022
Golang implementation of the Raft consensus protocol

raft raft is a Go library that manages a replicated log and can be used with an FSM to manage replicated state machines. It is a library for providing

HashiCorp 6.5k Nov 22, 2022
The pure golang implementation of nanomsg (version 1, frozen)

mangos NOTE: This is the legacy version of mangos (v1). Users are encouraged to use mangos v2 instead if possible. No further development is taking pl

nanomsg 1.5k Nov 25, 2022
A Golang implementation of the Umee network, a decentralized universal capital facility in the Cosmos ecosystem.

Umee A Golang implementation of the Umee network, a decentralized universal capital facility in the Cosmos ecosystem. Umee is a Universal Capital Faci

null 161 Nov 17, 2022
Kafka implemented in Golang with built-in coordination (No ZK dep, single binary install, Cloud Native)

Jocko Kafka/distributed commit log service in Go. Goals of this project: Implement Kafka in Go Protocol compatible with Kafka so Kafka clients and ser

Travis Jeffery 4.7k Nov 28, 2022
a Framework for creating microservices using technologies and design patterns of Erlang/OTP in Golang

Technologies and design patterns of Erlang/OTP have been proven over the years. Now in Golang. Up to x5 times faster than original Erlang/OTP in terms

Taras Halturin 1.9k Nov 26, 2022
Golang implementation of distributed mutex on Azure lease blobs

Distributed Mutex on Azure Lease Blobs This package implements distributed lock available for multiple processes. Possible use-cases include exclusive

YouScan 11 Jul 31, 2022