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

程序名称:pbgo

授权协议: BSD

操作系统: 跨平台

开发语言: Google Go

pbgo 介绍

基于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

pbgo 官网

https://github.com/chai2010/pbgo

相关编程语言

MuPlayer 是一款跨平台、轻量级的音频播放解决方案,...
OS FLV 是一个 开源和可嵌入网页的flv播放器。 这个...
DewPlayer音乐播放器,样式很简单,而且很实用.播放器...
JW FLV MEDIA PLAYER是一个开源的在网页上使用的Fla...
Speakker 是一个基于 Web 浏览器的音乐播放器,只提...
Player Framework 是一个开源的支持 HTML5 的视频播...