《Packt.Mastering.Go.Web.Services.2015.4.pdf》之Using Gorilla for JSON-RPC
来源:互联网 发布:ipad上的淘宝怎么横屏 编辑:程序博客网 时间:2024/06/07 18:28
官网
http://www.gorillatoolkit.org/pkg/rpc#subdirs
测试代码
为了更好的说明使用方法,对原文的代码有所修改。
type RPCAPIArguments struct { Message string Msg string}type RPCAPIResponse struct { Message string Masg string}type StringService struct{}func (h *StringService) Length(r *http.Request, arguments *RPCAPIArguments, reply *RPCAPIResponse) error { Debug(r.Header) Debug(arguments.Message) Debug(arguments.Msg) reply.Message = "Your string is " + fmt.Sprintf("Your string is%d chars long", utf8.RuneCountInString(arguments.Message)) + "characters long" reply.Masg = "er" return nil}func f(i *rpc.RequestInfo) { Debug("fucn") return}func main() { fmt.Println("Starting service") // s := rpc.NewServer() // s.RegisterCodec(json.NewCodec(), "application/json") // s.RegisterService(new(StringService), "") s := rpc.NewServer() s.RegisterCodec(json.NewCodec(), "application/json") s.RegisterService(new(StringService), "") s.RegisterAfterFunc(f) http.Handle("/rpc", s) http.ListenAndServe(":10000", nil)}
测试请求
{ "method": "StringService.Length", "params": [ { "Message": "Testing therservied", "Msg": "sbig" } ], "id": "3"}
响应
{ "result": { "Message": "Your string is Your string is19 chars longcharacters long", "Masg": "er" }, "error": null, "id": "3"}
说明:
在POST数据中,method指定要远程执行的方法,StringService.Length对应服务器中的StringService类型的Length方法。通过
s.RegisterService(new(StringService), "")
将StringService注册到RPC。
params指定传递的参数,分别对应StringService的两个成员变量 Message,Msg。
0 0
- 《Packt.Mastering.Go.Web.Services.2015.4.pdf》之Using Gorilla for JSON-RPC
- Using gsoap for web services
- Mastering Web Services Security
- Using gsoap for web services in symbian
- Go语言学习之JSON RPC
- The Python web services developer: XML-RPC for Python
- Mastering Web Application Development with AngularJS-Packt 2013 读书笔记(不错的好书!)
- Using Web Services for Remoting over the Internet.
- Using Web Services for Remoting over the Internet.
- Using dispatch groups to wait for multiple web services
- Pro PowerShell for Amazon Web Services.pdf 英文原版 免费下载
- Using Web Services Effectively
- Using Windows Web Services
- Web services (pdf)
- Web Services:Apache XML-RPC
- RPC,RMI,Web Services,JMS
- Web Services:Apache XML-RPC
- Spring之集成之Remoting and web services using Spring
- 三天工作总结
- vue2中的组件component问题
- Python的星号(*、**)的作用
- 【Java基础】线程笔记——线程安全
- 为什么magento(麦进斗)怎么慢
- 《Packt.Mastering.Go.Web.Services.2015.4.pdf》之Using Gorilla for JSON-RPC
- .net中lock的用途
- 一看就懂的自定义View -- 水波纹圆形进度球
- 鸡兔同笼问题
- 快速排序的改进-随机快速排序
- db2 10.1 数据库文件介绍
- CSP历届真题分类
- 您的设计模式——命令模式【Command Pattern 】
- 通过GCC编译器编译c语言