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

Hprose

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

Introduction

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.

Owner
Hprose
Hprose is a High Performance Remote Object Service Engine.
Hprose
Comments
  • 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
    https://github.com/hprose/hprose-go/blob/master/hprose/reader.go#L407
    https://github.com/hprose/hprose-go/blob/master/hprose/reader.go#L1751

    不知道这里是一个疏忽还是有意为之的结果?

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

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

    在golang做server,用js调用遇到跨域问题怎么解决?

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

    func (e event) OnSendHeader(ctx rpc.HTTPContext) { ctx.Response.Header().Set("Access-Control-Allow-Origin", "http://127.0.0.1:8081"); 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) {
        dispatch(userGetSuccess(resp.data));
      } else {
        dispatch(userGetFailure(resp.message));
      }
    }, (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 'http://127.0.0.1:9876/api' from origin 'http://127.0.0.1:8081' has been blocked by CORS policy: Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response. 请问问题到底出现在哪?我是不是哪里写错了?貌似onSendHeader没有起到作用,求解决。

  • 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正确调用。但目前这点无法保证。

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

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

    服务端代码 ` 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方法,

  • 参数传输性能较低

    参数传输性能较低

    // 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://127.0.0.1:2212") 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://127.0.0.1:2212")

    var ro *Stub
    client.UseService(&ro)
    paras := make([]int, 10000000)
    
    for {
        startTm := time.Now().UnixNano()
    
        ro.WriteParas(paras)
    
        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 处理效率较低

  • 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("http://127.0.0.1:8080")

    var ro *Stub
    client.UseService(&ro)
    
    aa := ro.GetMeasList()
    fmt.Println(aa)
    

    }

    it can work well, why?

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

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

    code

        fmt.Println(global.LogId)
    global.LogId = strconv.FormatInt(rand.Int63(),10)
    time.Sleep(time.Duration(8)*time.Second)
    pUser, _ := model.SpecialUsers.UserList(where, AWhere, page, pageSize)
    fmt.Println(global.LogId)
    

    5577006791947779410 5577006791947779410 8674665223082153551 8674665223082153551 6129484611666145821

    咋回事呢,qq群有管理吗申请好几天没有通过

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

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

    目前的通讯操作大部分都是长连接,所以还是需要一个类似于connect的连接服务接口函数,可以判断对于服务的连接状况,这样也便于下一步的数据操作。
    现在的接口实现是要在具体接口函数调用时返回连接状态信息,使用较别扭,只能自己增加一个函数用于判断连接状况,能否在NewClient函数调用中就开始建立连接,并将连接放入连接池中,并将连接信息通过error返回?
    
  • 如何支持可变的方法返回值?

    如何支持可变的方法返回值?

    你好,下面是部分的Client代码:

    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?

    多谢🙏🙏🙏

  • 如何在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的调用?

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

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

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

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

    for i:=0; i<8 ; i++ {
    	fmt.Println(stub.Hello("world"))
    }
    
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

Dec 19, 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

Dec 17, 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

Dec 15, 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

Dec 28, 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

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

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

Dec 16, 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

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

Dec 29, 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

Nov 17, 2022
Dec 27, 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

Jan 9, 2023
The pure golang implementation of nanomsg (version 1, frozen)
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

Dec 7, 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

Jan 3, 2023
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

Dec 28, 2022
a Framework for creating microservices using technologies and design patterns of Erlang/OTP in Golang
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

Dec 28, 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

Jul 31, 2022