use protoc3.0 instead of protoc2.6

master
shengxiang 9 years ago
parent e038b0e2a7
commit 61e2c2b648

@ -63,6 +63,10 @@ I decide to use [grpc](http://www.grpc.io/) in 2015-09-05
go get -u -v github.com/golang/protobuf/{proto,protoc-gen-go}
pbrpc/codegen.sh
**Need protoc 3.0** <http://www.cnblogs.com/yuhan-TB/p/4629362.html>
Do not use `brew install protobuf`, this will only install protoc 2.6
# Design
Has a folder `.gosuv` under `$HOME` path.

@ -15,7 +15,6 @@ import (
"github.com/codegangsta/inject"
pb "github.com/codeskyblue/gosuv/gosuvpb"
"github.com/franela/goreq"
"github.com/golang/protobuf/proto"
"github.com/qiniu/log"
"golang.org/x/net/context"
"google.golang.org/grpc"
@ -96,7 +95,7 @@ func StatusAction(client pb.GoSuvClient) {
log.Fatal(err)
}
for _, ps := range res.GetPrograms() {
fmt.Printf("%-10s\t%-8s\t%s\n", ps.GetName(), ps.GetStatus(), ps.GetExtra())
fmt.Printf("%-10s\t%-8s\t%s\n", ps.Name, ps.Status, ps.Extra)
}
}
@ -158,11 +157,11 @@ func StopAction(ctx *cli.Context) {
name := ctx.Args().First()
client := pb.NewProgramClient(conn)
res, err := client.Stop(context.Background(), &pb.Request{Name: proto.String(name)})
res, err := client.Stop(context.Background(), &pb.Request{Name: name})
if err != nil {
Errorf("ERR: %#v\n", err)
}
fmt.Println(res.GetMessage())
fmt.Println(res.Message)
}
func Errorf(format string, v ...interface{}) {
@ -179,11 +178,11 @@ func StartAction(ctx *cli.Context) {
name := ctx.Args().First()
client := pb.NewProgramClient(conn)
res, err := client.Start(context.Background(), &pb.Request{Name: proto.String(name)})
res, err := client.Start(context.Background(), &pb.Request{Name: name})
if err != nil {
Errorf("ERR: %#v\n", err)
}
fmt.Println(res.GetMessage())
fmt.Println(res.Message)
}
// grpc.Dial can't set network, so I have to implement this func
@ -207,7 +206,7 @@ func ShutdownAction(ctx *cli.Context) {
if err != nil {
log.Fatal(err)
}
fmt.Println(res.GetMessage())
fmt.Println(res.Message)
}
func VersionAction(ctx *cli.Context, client pb.GoSuvClient) {
@ -216,7 +215,7 @@ func VersionAction(ctx *cli.Context, client pb.GoSuvClient) {
if err != nil {
log.Fatal(err)
}
fmt.Printf("Server: %s\n", res.GetMessage())
fmt.Printf("Server: %s\n", res.Message)
}
var app *cli.App

@ -15,6 +15,7 @@ It has these top-level messages:
ProgramInfo
ProgramStatus
StatusResponse
LogLine
*/
package gosuvpb
@ -33,7 +34,6 @@ var _ = fmt.Errorf
var _ = math.Inf
type NopRequest struct {
XXX_unrecognized []byte `json:"-"`
}
func (m *NopRequest) Reset() { *m = NopRequest{} }
@ -41,112 +41,44 @@ func (m *NopRequest) String() string { return proto.CompactTextString(m) }
func (*NopRequest) ProtoMessage() {}
type Response struct {
Code *int32 `protobuf:"varint,1,opt,name=code" json:"code,omitempty"`
Message *string `protobuf:"bytes,2,opt,name=message" json:"message,omitempty"`
XXX_unrecognized []byte `json:"-"`
Code int32 `protobuf:"varint,1,opt,name=code" json:"code,omitempty"`
Message string `protobuf:"bytes,2,opt,name=message" json:"message,omitempty"`
}
func (m *Response) Reset() { *m = Response{} }
func (m *Response) String() string { return proto.CompactTextString(m) }
func (*Response) ProtoMessage() {}
func (m *Response) GetCode() int32 {
if m != nil && m.Code != nil {
return *m.Code
}
return 0
}
func (m *Response) GetMessage() string {
if m != nil && m.Message != nil {
return *m.Message
}
return ""
}
type Request struct {
Name *string `protobuf:"bytes,1,req,name=name" json:"name,omitempty"`
XXX_unrecognized []byte `json:"-"`
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
}
func (m *Request) Reset() { *m = Request{} }
func (m *Request) String() string { return proto.CompactTextString(m) }
func (*Request) ProtoMessage() {}
func (m *Request) GetName() string {
if m != nil && m.Name != nil {
return *m.Name
}
return ""
}
type ProgramInfo struct {
Name *string `protobuf:"bytes,1,req,name=name" json:"name,omitempty"`
Command []string `protobuf:"bytes,2,rep,name=command" json:"command,omitempty"`
Dir *string `protobuf:"bytes,3,req,name=dir" json:"dir,omitempty"`
XXX_unrecognized []byte `json:"-"`
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
Command string `protobuf:"bytes,2,opt,name=command" json:"command,omitempty"`
Dir string `protobuf:"bytes,3,opt,name=dir" json:"dir,omitempty"`
}
func (m *ProgramInfo) Reset() { *m = ProgramInfo{} }
func (m *ProgramInfo) String() string { return proto.CompactTextString(m) }
func (*ProgramInfo) ProtoMessage() {}
func (m *ProgramInfo) GetName() string {
if m != nil && m.Name != nil {
return *m.Name
}
return ""
}
func (m *ProgramInfo) GetCommand() []string {
if m != nil {
return m.Command
}
return nil
}
func (m *ProgramInfo) GetDir() string {
if m != nil && m.Dir != nil {
return *m.Dir
}
return ""
}
type ProgramStatus struct {
Name *string `protobuf:"bytes,1,req,name=name" json:"name,omitempty"`
Status *string `protobuf:"bytes,2,req,name=status" json:"status,omitempty"`
Extra *string `protobuf:"bytes,3,opt,name=extra" json:"extra,omitempty"`
XXX_unrecognized []byte `json:"-"`
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
Status string `protobuf:"bytes,2,opt,name=status" json:"status,omitempty"`
Extra string `protobuf:"bytes,3,opt,name=extra" json:"extra,omitempty"`
}
func (m *ProgramStatus) Reset() { *m = ProgramStatus{} }
func (m *ProgramStatus) String() string { return proto.CompactTextString(m) }
func (*ProgramStatus) ProtoMessage() {}
func (m *ProgramStatus) GetName() string {
if m != nil && m.Name != nil {
return *m.Name
}
return ""
}
func (m *ProgramStatus) GetStatus() string {
if m != nil && m.Status != nil {
return *m.Status
}
return ""
}
func (m *ProgramStatus) GetExtra() string {
if m != nil && m.Extra != nil {
return *m.Extra
}
return ""
}
type StatusResponse struct {
Programs []*ProgramStatus `protobuf:"bytes,1,rep,name=programs" json:"programs,omitempty"`
XXX_unrecognized []byte `json:"-"`
Programs []*ProgramStatus `protobuf:"bytes,1,rep,name=programs" json:"programs,omitempty"`
}
func (m *StatusResponse) Reset() { *m = StatusResponse{} }
@ -160,6 +92,14 @@ func (m *StatusResponse) GetPrograms() []*ProgramStatus {
return nil
}
type LogLine struct {
Line string `protobuf:"bytes,1,opt,name=line" json:"line,omitempty"`
}
func (m *LogLine) Reset() { *m = LogLine{} }
func (m *LogLine) String() string { return proto.CompactTextString(m) }
func (*LogLine) ProtoMessage() {}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn

@ -1,39 +1,46 @@
syntax = "proto3";
package gosuvpb;
message NopRequest {}
message Response {
optional int32 code = 1;
optional string message = 2;
int32 code = 1;
string message = 2;
}
message Request {
required string name = 1;
string name = 1;
}
message ProgramInfo {
required string name = 1;
repeated string command = 2;
required string dir = 3;
string name = 1;
string command = 2;
string dir = 3;
}
message ProgramStatus {
required string name = 1;
required string status = 2;
optional string extra = 3;
string name = 1;
string status = 2;
string extra = 3;
}
message StatusResponse {
repeated ProgramStatus programs = 1;
}
message LogLine {
string line = 1;
}
service GoSuv {
rpc Shutdown(NopRequest) returns (Response) {};
rpc Version(NopRequest) returns (Response) {};
rpc Status(NopRequest) returns (StatusResponse) {};
rpc Shutdown(NopRequest) returns (Response) {}
rpc Version(NopRequest) returns (Response) {}
rpc Status(NopRequest) returns (StatusResponse) {}
}
service Program {
rpc Start(Request) returns (Response) {};
rpc Stop(Request) returns (Response) {};
rpc Start(Request) returns (Response) {}
rpc Stop(Request) returns (Response) {}
//rpc Tail(Request) returns (stream LogLine) {}
}

@ -6,7 +6,6 @@ import (
"time"
pb "github.com/codeskyblue/gosuv/gosuvpb"
"github.com/golang/protobuf/proto"
"golang.org/x/net/context"
)
@ -15,23 +14,23 @@ type PbProgram struct {
func (this *PbProgram) Start(ctx context.Context, in *pb.Request) (res *pb.Response, err error) {
res = &pb.Response{}
program, err := programTable.Get(in.GetName())
program, err := programTable.Get(in.Name)
if err != nil {
return
}
program.InputData(EVENT_START)
res.Message = proto.String(in.GetName() + ": started")
res.Message = in.Name + ": started"
return res, nil
}
func (this *PbProgram) Stop(ctx context.Context, in *pb.Request) (res *pb.Response, err error) {
res = &pb.Response{}
program, err := programTable.Get(in.GetName())
program, err := programTable.Get(in.Name)
if err != nil {
return
}
program.InputData(EVENT_STOP)
res.Message = proto.String(in.GetName() + ": stopped")
res.Message = in.Name + ": stopped"
return res, nil
}
@ -47,13 +46,13 @@ func (s *PbSuvServer) Shutdown(ctx context.Context, in *pb.NopRequest) (*pb.Resp
os.Exit(2)
}()
res := &pb.Response{}
res.Message = proto.String("gosuv shutdown")
res.Message = "gosuv shutdown"
return res, nil
}
func (s *PbSuvServer) Version(ctx context.Context, in *pb.NopRequest) (res *pb.Response, err error) {
res = &pb.Response{
Message: proto.String(GOSUV_VERSION),
Message: GOSUV_VERSION,
}
return
}
@ -62,9 +61,9 @@ func (s *PbSuvServer) Status(ctx context.Context, in *pb.NopRequest) (res *pb.St
res = &pb.StatusResponse{}
for _, program := range programTable.Programs() {
ps := &pb.ProgramStatus{}
ps.Name = proto.String(program.Info.Name)
ps.Status = proto.String(program.Status)
ps.Extra = proto.String("...")
ps.Name = program.Info.Name
ps.Status = program.Status
ps.Extra = "..."
res.Programs = append(res.Programs, ps)
}
return

Loading…
Cancel
Save