基于 Protobuf 的 RPC/REST 迷你框架 pbgo

码农软件 · 软件分类 · REST/RESTful项目 · 2019-03-10 16:28:38

软件介绍

基于Protobuf定义接口规范,通过pbgo提供的插件生成RPC和REST相关代码。

创建hello.proto文件,定义接口规范:

syntax = "proto3";
package hello_pb;

import "github.com/chai2010/pbgo/pbgo.proto";

message String {
    string value = 1;
}

service EchoService {
    rpc Echo (String) returns (String) {
        option (pbgo.rest_api) = {
            get: "/echo/:value"
        };
    }
}

用pbgo插件生成代码:

$ protoc -I=. -I=$(GOPATH)/src --pbgo_out=. hello.proto

创建REST服务:

type EchoService struct{}

func (p *EchoService) Echo(request *hello_pb.String, reply *hello_pb.String) error {
    *reply = *request
    return nil
}

func main() {
    router := hello_pb.EchoServiceHandler(new(EchoService))
    log.Fatal(http.ListenAndServe(":8080", router))
}

测试REST服务:

$ curl localhost:8080/echo/gopher
{"value":"gopher"}

$ curl localhost:8080/echo/gopher?value=cgo
{"value":"cgo"}

详细的例子请参考:https://github.com/chai2010/pbgo/blob/master/examples/hello.p

本文地址:https://codercto.com/soft/d/1051.html

反欺骗的艺术

反欺骗的艺术

(美) 米特尼克(Mitnick, K. D.) / 潘爱民 / 清华大学出版社 / 2014-7-1 / 49.80元

凯文•米特尼克(Kevin D. Mitnick)曾经是历史上最令FBI头痛的计算机顽徒之一,现在他已经完成了大量的文章、图书、影片和记录文件。自从2000年从联邦监狱中获释以来,米特尼克改变了他的生活方式,成了全球广受欢迎的计算机安全专家之一。在他的首部将功补过的作品中,这位全世界最著名的黑客为“放下屠刀,立地成佛”这句佛语赋予了新的含义。 在《反欺骗的艺术——世界传奇黑客的经历分享》中,......一起来看看 《反欺骗的艺术》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试