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} go get -u -v github.com/golang/protobuf/{proto,protoc-gen-go}
pbrpc/codegen.sh 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 # Design
Has a folder `.gosuv` under `$HOME` path. Has a folder `.gosuv` under `$HOME` path.

@ -15,7 +15,6 @@ import (
"github.com/codegangsta/inject" "github.com/codegangsta/inject"
pb "github.com/codeskyblue/gosuv/gosuvpb" pb "github.com/codeskyblue/gosuv/gosuvpb"
"github.com/franela/goreq" "github.com/franela/goreq"
"github.com/golang/protobuf/proto"
"github.com/qiniu/log" "github.com/qiniu/log"
"golang.org/x/net/context" "golang.org/x/net/context"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -96,7 +95,7 @@ func StatusAction(client pb.GoSuvClient) {
log.Fatal(err) log.Fatal(err)
} }
for _, ps := range res.GetPrograms() { 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() name := ctx.Args().First()
client := pb.NewProgramClient(conn) 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 { if err != nil {
Errorf("ERR: %#v\n", err) Errorf("ERR: %#v\n", err)
} }
fmt.Println(res.GetMessage()) fmt.Println(res.Message)
} }
func Errorf(format string, v ...interface{}) { func Errorf(format string, v ...interface{}) {
@ -179,11 +178,11 @@ func StartAction(ctx *cli.Context) {
name := ctx.Args().First() name := ctx.Args().First()
client := pb.NewProgramClient(conn) 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 { if err != nil {
Errorf("ERR: %#v\n", err) 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 // 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 { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
fmt.Println(res.GetMessage()) fmt.Println(res.Message)
} }
func VersionAction(ctx *cli.Context, client pb.GoSuvClient) { func VersionAction(ctx *cli.Context, client pb.GoSuvClient) {
@ -216,7 +215,7 @@ func VersionAction(ctx *cli.Context, client pb.GoSuvClient) {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
fmt.Printf("Server: %s\n", res.GetMessage()) fmt.Printf("Server: %s\n", res.Message)
} }
var app *cli.App var app *cli.App

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

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

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

Loading…
Cancel
Save