Giter Site home page Giter Site logo

sunquakes / jsonrpc4go Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 4.0 181 KB

A go client and server over http or tcp implementation of JSON-RPC 2.0. Support consul & nacos.

Home Page: https://www.moonquakes.io/guide/golang.html

License: Apache License 2.0

Go 99.79% Lua 0.07% Shell 0.14%
golang go jsonrpc jsonrpc2 client http json-rpc2 server tcp consul

jsonrpc4go's People

Contributors

sunquakes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jsonrpc4go's Issues

关于前置func和后置func

image
你好,项目作者。希望这里能增加两个func,用来预处理rpc请求前置和后置。例如:
注册一个前置func,用来鉴定请求权限。
注册一个后置func,用来记录rpc日志。
等等。。。

tcp server cpu飙升

1.启动服务
s, _ := jsonrpc4go.NewServer("tcp", "127.0.0.1", "3232") 
s.Register(new(IntRpc))
s.Start()
2.请求
result := new(Result)
c, _ := jsonrpc4go.NewClient("tcp", "127.0.0.1", "3232")
err := c.Call(...)

cpu会飙升

tcp客户端接收数据不完整

问题:tcp数据分包后,一次read接收不完整。需要接收多次,每次判断数据中是否有结束符。
文件:client/tcp.go
方法:handleFunc

解决方法

// 定义接收buffer
	var (
		buf = make([]byte, p.Options.PackageMaxLength)
		tmp = make([]byte, 1024)
		num = 0
	)

	// 接收数据
	for {
		n, err := p.Conn.Read(tmp)
		if err != nil {
			return err
		}
		buf = append(buf, tmp[:n]...)
		num = len(buf)
		// 判断是否结束
		if reflect.DeepEqual(buf[num-2:], []byte(p.Options.PackageEof)) {
			break
		}
	}
	// 截取掉结束符
	eofLen := len([]byte(p.Options.PackageEof))
	buf = buf[:num-eofLen]
	// 移除切面填充的0
	buf = bytes.Trim(buf, "\x00")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.