try to use protobuf

master
shengxiang 9 years ago
parent 29d17f55c3
commit 96883fc81e

@ -37,6 +37,14 @@ There is a directory `showpid`
When run `gosuv showpid`, file `run` will be called.
# RPC Design
I decide to use protobuf in 2015-09-05
<https://github.com/golang/protobuf>
go get -u -v github.com/golang/protobuf/{proto,protoc-gen-go}
cd pbrpc; protoc --go_out=. *.proto
# Design
Has a folder `.gosuv` under `$HOME` path.

@ -151,7 +151,12 @@ func buildURI(ctx *cli.Context, uri string) string {
ctx.GlobalString("host"), ctx.GlobalInt("port"), uri)
}
func buildpbURI(ctx *cli.Context) string {
return buildURI(ctx, "/protobuf")
}
func StopAction(ctx *cli.Context) {
log.Println(buildpbURI(ctx))
}
func ShutdownAction(ctx *cli.Context) {

@ -0,0 +1,64 @@
// Code generated by protoc-gen-go.
// source: gosuv.proto
// DO NOT EDIT!
/*
Package pbrpc is a generated protocol buffer package.
It is generated from these files:
gosuv.proto
It has these top-level messages:
CtrlRequest
CtrlResponse
*/
package pbrpc
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
type CtrlRequest struct {
Name *string `protobuf:"bytes,1,req,name=name" json:"name,omitempty"`
Key *string `protobuf:"bytes,2,req,name=key" json:"key,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *CtrlRequest) Reset() { *m = CtrlRequest{} }
func (m *CtrlRequest) String() string { return proto.CompactTextString(m) }
func (*CtrlRequest) ProtoMessage() {}
func (m *CtrlRequest) GetName() string {
if m != nil && m.Name != nil {
return *m.Name
}
return ""
}
func (m *CtrlRequest) GetKey() string {
if m != nil && m.Key != nil {
return *m.Key
}
return ""
}
type CtrlResponse struct {
Value *string `protobuf:"bytes,1,opt,name=value" json:"value,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *CtrlResponse) Reset() { *m = CtrlResponse{} }
func (m *CtrlResponse) String() string { return proto.CompactTextString(m) }
func (*CtrlResponse) ProtoMessage() {}
func (m *CtrlResponse) GetValue() string {
if m != nil && m.Value != nil {
return *m.Value
}
return ""
}

@ -0,0 +1,15 @@
package pbrpc;
message CtrlRequest {
required string name = 1;
required string key = 2; // not actually required/guaranteed to be UTF-8
}
message CtrlResponse {
optional string value = 1;
}
service GoSUV{
rpc Control(CtrlRequest) returns (CtrlResponse) {
};
}
Loading…
Cancel
Save