From 218f25ab567c0f71703630f49c900d18b6414eea Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Tue, 13 Dec 2016 10:27:52 +0100 Subject: [PATCH 1/7] Add go-kit example proto definitions --- .../go-kit/services/session/session.proto | 26 +++++++++++++ examples/go-kit/services/sprint/sprint.proto | 38 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 examples/go-kit/services/session/session.proto create mode 100644 examples/go-kit/services/sprint/sprint.proto diff --git a/examples/go-kit/services/session/session.proto b/examples/go-kit/services/session/session.proto new file mode 100644 index 0000000..7935967 --- /dev/null +++ b/examples/go-kit/services/session/session.proto @@ -0,0 +1,26 @@ +syntax "proto3"; + +package session; + +service SessionService { + rpc Login(LoginRequest) returns (LoginResponse) {} + rpc Logout(LogoutRequest) returns (LogoutResponse) {} +} + +message LoginRequest { + string username = 1; + string password = 2; +} + +message LoginResponse { + string token = 1; + string err_msg = 2; +} + +message LogoutRequest { + string token = 1; +} + +message LogoutResponse { + string err_msg = 1; +} \ No newline at end of file diff --git a/examples/go-kit/services/sprint/sprint.proto b/examples/go-kit/services/sprint/sprint.proto new file mode 100644 index 0000000..001daad --- /dev/null +++ b/examples/go-kit/services/sprint/sprint.proto @@ -0,0 +1,38 @@ +syntax "proto3"; + +package sprint; + +service SprintService { + rpc AddSprint(AddSprintRequest) returns AddSprintResponse {} + rpc CloseSprint(CloseSprintRequest) returns CloseSprintResponse {} + rpc GetSprint(GetSprintRequest) returns GetSprintResponse {} +} + +message AddSprintRequest { + string name = 1; +} +message AddSprintResponse { + Sprint sprint = 1; + string err_msg = 2; +} + +message CloseSprintRequest { + string id = 1; +} +message CloseSprintResponse { + string err_msg = 1; +} + +message GetSprintRequest { + string id = 1; +} +message GetSprintResponse { + Sprint sprint = 1; + string err_msg = 2; +} + +message Sprint { + string id = 1; + uint32 created_at = 2; + string name = 3; +} \ No newline at end of file From ce8f7bd8a710f86a49327109e602a8d0f8541f4e Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Tue, 13 Dec 2016 10:36:55 +0100 Subject: [PATCH 2/7] Add Makefile --- examples/go-kit/Makefile | 14 ++ .../output/services/session/session.pb.go | 98 ++++++++++++ .../output/services/sprint/sprint.pb.go | 151 ++++++++++++++++++ .../session/services/session/session.pb.go | 98 ++++++++++++ .../go-kit/services/session/session.proto | 2 +- .../sprint/services/sprint/sprint.pb.go | 151 ++++++++++++++++++ examples/go-kit/services/sprint/sprint.proto | 8 +- 7 files changed, 517 insertions(+), 5 deletions(-) create mode 100644 examples/go-kit/Makefile create mode 100644 examples/go-kit/output/services/session/session.pb.go create mode 100644 examples/go-kit/output/services/sprint/sprint.pb.go create mode 100644 examples/go-kit/services/session/services/session/session.pb.go create mode 100644 examples/go-kit/services/sprint/services/sprint/sprint.pb.go diff --git a/examples/go-kit/Makefile b/examples/go-kit/Makefile new file mode 100644 index 0000000..a9ffa0d --- /dev/null +++ b/examples/go-kit/Makefile @@ -0,0 +1,14 @@ +SOURCES := $(shell find . -name "*.proto" -not -path ./vendor/\*) + +TARGETS_GO := $(foreach source, $(SOURCES), $(source)_go) +TARGETS_TMPL := $(foreach source, $(SOURCES), $(source)_tmpl) + +.PHONY: build +build: $(TARGETS_GO) $(TARGETS_TMPL) + +$(TARGETS_GO): %_go: + protoc --gogo_out="$(dir $*)" "$*" + +$(TARGETS_TMPL): %_tmpl: + @mkdir -p $(dir $*)gen + protoc -I. --gotemplate_out=template_dir=templates:output "$*" diff --git a/examples/go-kit/output/services/session/session.pb.go b/examples/go-kit/output/services/session/session.pb.go new file mode 100644 index 0000000..ca98145 --- /dev/null +++ b/examples/go-kit/output/services/session/session.pb.go @@ -0,0 +1,98 @@ +// Code generated by protoc-gen-go. +// source: services/session/session.proto +// DO NOT EDIT! + +/* +Package session is a generated protocol buffer package. + +It is generated from these files: + services/session/session.proto + +It has these top-level messages: + LoginRequest + LoginResponse + LogoutRequest + LogoutResponse +*/ +package session + +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 + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +type LoginRequest struct { + Username string `protobuf:"bytes,1,opt,name=username" json:"username,omitempty"` + Password string `protobuf:"bytes,2,opt,name=password" json:"password,omitempty"` +} + +func (m *LoginRequest) Reset() { *m = LoginRequest{} } +func (m *LoginRequest) String() string { return proto.CompactTextString(m) } +func (*LoginRequest) ProtoMessage() {} +func (*LoginRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } + +type LoginResponse struct { + Token string `protobuf:"bytes,1,opt,name=token" json:"token,omitempty"` + ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg" json:"err_msg,omitempty"` +} + +func (m *LoginResponse) Reset() { *m = LoginResponse{} } +func (m *LoginResponse) String() string { return proto.CompactTextString(m) } +func (*LoginResponse) ProtoMessage() {} +func (*LoginResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } + +type LogoutRequest struct { + Token string `protobuf:"bytes,1,opt,name=token" json:"token,omitempty"` +} + +func (m *LogoutRequest) Reset() { *m = LogoutRequest{} } +func (m *LogoutRequest) String() string { return proto.CompactTextString(m) } +func (*LogoutRequest) ProtoMessage() {} +func (*LogoutRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } + +type LogoutResponse struct { + ErrMsg string `protobuf:"bytes,1,opt,name=err_msg,json=errMsg" json:"err_msg,omitempty"` +} + +func (m *LogoutResponse) Reset() { *m = LogoutResponse{} } +func (m *LogoutResponse) String() string { return proto.CompactTextString(m) } +func (*LogoutResponse) ProtoMessage() {} +func (*LogoutResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } + +func init() { + proto.RegisterType((*LoginRequest)(nil), "session.LoginRequest") + proto.RegisterType((*LoginResponse)(nil), "session.LoginResponse") + proto.RegisterType((*LogoutRequest)(nil), "session.LogoutRequest") + proto.RegisterType((*LogoutResponse)(nil), "session.LogoutResponse") +} + +func init() { proto.RegisterFile("services/session/session.proto", fileDescriptor0) } + +var fileDescriptor0 = []byte{ + // 231 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x6c, 0x50, 0xcb, 0x4a, 0xc5, 0x30, + 0x10, 0x35, 0xc2, 0xed, 0xd5, 0x41, 0xef, 0x62, 0x50, 0x6f, 0xe9, 0x42, 0x24, 0x20, 0xe8, 0xa6, + 0x82, 0x6e, 0x04, 0xc1, 0xa5, 0x2b, 0xdd, 0xb4, 0x1f, 0x20, 0x55, 0x87, 0x52, 0xa4, 0x99, 0x3a, + 0x93, 0xea, 0x27, 0xf8, 0xdb, 0x62, 0x93, 0x68, 0x7d, 0xac, 0xc2, 0xc9, 0xcc, 0x79, 0xcc, 0x81, + 0x43, 0x25, 0x79, 0xed, 0x1e, 0x49, 0xcf, 0x94, 0x54, 0x3b, 0x76, 0xe9, 0x2d, 0x07, 0x61, 0xcf, + 0xb8, 0x8c, 0xd0, 0xde, 0xc0, 0xce, 0x2d, 0xb7, 0x9d, 0xab, 0xe8, 0x65, 0x24, 0xf5, 0x58, 0xc0, + 0xd6, 0xa8, 0x24, 0xae, 0xe9, 0x29, 0x37, 0x47, 0xe6, 0x64, 0xbb, 0xfa, 0xc2, 0x9f, 0xb3, 0xa1, + 0x51, 0x7d, 0x63, 0x79, 0xca, 0x37, 0xc3, 0x2c, 0x61, 0x7b, 0x0d, 0xbb, 0x51, 0x47, 0x07, 0x76, + 0x4a, 0xb8, 0x07, 0x0b, 0xcf, 0xcf, 0xe4, 0xa2, 0x4a, 0x00, 0xb8, 0x86, 0x25, 0x89, 0xdc, 0xf7, + 0xda, 0x46, 0x85, 0x8c, 0x44, 0xee, 0xb4, 0xb5, 0xc7, 0x13, 0x9f, 0x47, 0x9f, 0x82, 0xfc, 0xcb, + 0xb7, 0xa7, 0xb0, 0x4a, 0x6b, 0xd1, 0x67, 0xa6, 0x68, 0xe6, 0x8a, 0xe7, 0xef, 0x06, 0x56, 0x75, + 0xb8, 0xb2, 0x0e, 0x65, 0xe0, 0x25, 0x2c, 0xa6, 0x90, 0xb8, 0x5f, 0xa6, 0x3a, 0xe6, 0xc7, 0x17, + 0x07, 0xbf, 0xbf, 0x83, 0x87, 0xdd, 0xc0, 0x2b, 0xc8, 0x82, 0x2f, 0xfe, 0xd8, 0xf9, 0xce, 0x5b, + 0xac, 0xff, 0xfc, 0x27, 0xf2, 0x43, 0x36, 0x75, 0x7e, 0xf1, 0x11, 0x00, 0x00, 0xff, 0xff, 0xc7, + 0x91, 0x50, 0x79, 0x95, 0x01, 0x00, 0x00, +} diff --git a/examples/go-kit/output/services/sprint/sprint.pb.go b/examples/go-kit/output/services/sprint/sprint.pb.go new file mode 100644 index 0000000..41ccefe --- /dev/null +++ b/examples/go-kit/output/services/sprint/sprint.pb.go @@ -0,0 +1,151 @@ +// Code generated by protoc-gen-go. +// source: services/sprint/sprint.proto +// DO NOT EDIT! + +/* +Package sprint is a generated protocol buffer package. + +It is generated from these files: + services/sprint/sprint.proto + +It has these top-level messages: + AddSprintRequest + AddSprintResponse + CloseSprintRequest + CloseSprintResponse + GetSprintRequest + GetSprintResponse + Sprint +*/ +package sprint + +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 + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +type AddSprintRequest struct { + Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` +} + +func (m *AddSprintRequest) Reset() { *m = AddSprintRequest{} } +func (m *AddSprintRequest) String() string { return proto.CompactTextString(m) } +func (*AddSprintRequest) ProtoMessage() {} +func (*AddSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } + +type AddSprintResponse struct { + Sprint *Sprint `protobuf:"bytes,1,opt,name=sprint" json:"sprint,omitempty"` + ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg" json:"err_msg,omitempty"` +} + +func (m *AddSprintResponse) Reset() { *m = AddSprintResponse{} } +func (m *AddSprintResponse) String() string { return proto.CompactTextString(m) } +func (*AddSprintResponse) ProtoMessage() {} +func (*AddSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } + +func (m *AddSprintResponse) GetSprint() *Sprint { + if m != nil { + return m.Sprint + } + return nil +} + +type CloseSprintRequest struct { + Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` +} + +func (m *CloseSprintRequest) Reset() { *m = CloseSprintRequest{} } +func (m *CloseSprintRequest) String() string { return proto.CompactTextString(m) } +func (*CloseSprintRequest) ProtoMessage() {} +func (*CloseSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } + +type CloseSprintResponse struct { + ErrMsg string `protobuf:"bytes,1,opt,name=err_msg,json=errMsg" json:"err_msg,omitempty"` +} + +func (m *CloseSprintResponse) Reset() { *m = CloseSprintResponse{} } +func (m *CloseSprintResponse) String() string { return proto.CompactTextString(m) } +func (*CloseSprintResponse) ProtoMessage() {} +func (*CloseSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } + +type GetSprintRequest struct { + Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` +} + +func (m *GetSprintRequest) Reset() { *m = GetSprintRequest{} } +func (m *GetSprintRequest) String() string { return proto.CompactTextString(m) } +func (*GetSprintRequest) ProtoMessage() {} +func (*GetSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} } + +type GetSprintResponse struct { + Sprint *Sprint `protobuf:"bytes,1,opt,name=sprint" json:"sprint,omitempty"` + ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg" json:"err_msg,omitempty"` +} + +func (m *GetSprintResponse) Reset() { *m = GetSprintResponse{} } +func (m *GetSprintResponse) String() string { return proto.CompactTextString(m) } +func (*GetSprintResponse) ProtoMessage() {} +func (*GetSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} } + +func (m *GetSprintResponse) GetSprint() *Sprint { + if m != nil { + return m.Sprint + } + return nil +} + +type Sprint struct { + Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` + CreatedAt uint32 `protobuf:"varint,2,opt,name=created_at,json=createdAt" json:"created_at,omitempty"` + Name string `protobuf:"bytes,3,opt,name=name" json:"name,omitempty"` +} + +func (m *Sprint) Reset() { *m = Sprint{} } +func (m *Sprint) String() string { return proto.CompactTextString(m) } +func (*Sprint) ProtoMessage() {} +func (*Sprint) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} } + +func init() { + proto.RegisterType((*AddSprintRequest)(nil), "sprint.AddSprintRequest") + proto.RegisterType((*AddSprintResponse)(nil), "sprint.AddSprintResponse") + proto.RegisterType((*CloseSprintRequest)(nil), "sprint.CloseSprintRequest") + proto.RegisterType((*CloseSprintResponse)(nil), "sprint.CloseSprintResponse") + proto.RegisterType((*GetSprintRequest)(nil), "sprint.GetSprintRequest") + proto.RegisterType((*GetSprintResponse)(nil), "sprint.GetSprintResponse") + proto.RegisterType((*Sprint)(nil), "sprint.Sprint") +} + +func init() { proto.RegisterFile("services/sprint/sprint.proto", fileDescriptor0) } + +var fileDescriptor0 = []byte{ + // 290 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xac, 0x52, 0x4d, 0x4b, 0xc3, 0x40, + 0x10, 0x6d, 0xaa, 0x44, 0x32, 0xa5, 0xa5, 0x1d, 0x0f, 0xc6, 0xa8, 0x20, 0x8b, 0x14, 0x4f, 0x11, + 0xea, 0x2f, 0x68, 0x3d, 0x28, 0x88, 0x97, 0xb4, 0xf7, 0x12, 0xbb, 0x43, 0x09, 0xd8, 0x24, 0xee, + 0xac, 0xfe, 0x5f, 0xff, 0x89, 0xb0, 0xbb, 0xcd, 0x57, 0x8b, 0x27, 0x4f, 0xc9, 0xec, 0xbc, 0x7d, + 0x6f, 0xe6, 0xbd, 0x85, 0x6b, 0x26, 0xf5, 0x9d, 0x6d, 0x88, 0x1f, 0xb8, 0x54, 0x59, 0xae, 0xdd, + 0x27, 0x2e, 0x55, 0xa1, 0x0b, 0xf4, 0x6d, 0x25, 0xa6, 0x30, 0x9e, 0x4b, 0xb9, 0x34, 0x45, 0x42, + 0x9f, 0x5f, 0xc4, 0x1a, 0x11, 0x4e, 0xf3, 0x74, 0x47, 0xa1, 0x77, 0xeb, 0xdd, 0x07, 0x89, 0xf9, + 0x17, 0x2b, 0x98, 0x34, 0x70, 0x5c, 0x16, 0x39, 0x13, 0x4e, 0xc1, 0xd1, 0x18, 0xe8, 0x60, 0x36, + 0x8a, 0x9d, 0x86, 0xc3, 0xb9, 0x2e, 0x5e, 0xc0, 0x19, 0x29, 0xb5, 0xde, 0xf1, 0x36, 0xec, 0x1b, + 0x4e, 0x9f, 0x94, 0x7a, 0xe3, 0xad, 0xb8, 0x03, 0x7c, 0xfa, 0x28, 0x98, 0xda, 0xfa, 0x23, 0xe8, + 0x67, 0xd2, 0xa9, 0xf7, 0x33, 0x29, 0x62, 0x38, 0x6f, 0xa1, 0x9c, 0x7a, 0x83, 0xd5, 0x6b, 0xb1, + 0x0a, 0x18, 0x3f, 0x93, 0xfe, 0x9b, 0x73, 0x05, 0x93, 0x06, 0xe6, 0xbf, 0xf6, 0x79, 0x05, 0xdf, + 0x42, 0xbb, 0x7a, 0x78, 0x03, 0xb0, 0x51, 0x94, 0x6a, 0x92, 0xeb, 0x54, 0x9b, 0x5b, 0xc3, 0x24, + 0x70, 0x27, 0xf3, 0xda, 0xf2, 0x93, 0xda, 0xf2, 0xd9, 0x8f, 0x07, 0x43, 0xcb, 0xb6, 0xb4, 0x49, + 0xe2, 0x02, 0x82, 0x2a, 0x04, 0x0c, 0xf7, 0xc3, 0x75, 0xf3, 0x8b, 0x2e, 0x8f, 0x74, 0xec, 0x86, + 0xa2, 0x87, 0x2f, 0x30, 0x68, 0x98, 0x89, 0xd1, 0x1e, 0x7b, 0x98, 0x43, 0x74, 0x75, 0xb4, 0x57, + 0x31, 0x2d, 0x20, 0xa8, 0x2c, 0xac, 0xa7, 0xe9, 0x3a, 0x5f, 0x4f, 0x73, 0xe0, 0xb7, 0xe8, 0xbd, + 0xfb, 0xe6, 0x35, 0x3e, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x9e, 0xb2, 0x1e, 0xad, 0x02, + 0x00, 0x00, +} diff --git a/examples/go-kit/services/session/services/session/session.pb.go b/examples/go-kit/services/session/services/session/session.pb.go new file mode 100644 index 0000000..c07e0a0 --- /dev/null +++ b/examples/go-kit/services/session/services/session/session.pb.go @@ -0,0 +1,98 @@ +// Code generated by protoc-gen-gogo. +// source: services/session/session.proto +// DO NOT EDIT! + +/* +Package session is a generated protocol buffer package. + +It is generated from these files: + services/session/session.proto + +It has these top-level messages: + LoginRequest + LoginResponse + LogoutRequest + LogoutResponse +*/ +package session + +import proto "github.com/gogo/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 + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package + +type LoginRequest struct { + Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` + Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` +} + +func (m *LoginRequest) Reset() { *m = LoginRequest{} } +func (m *LoginRequest) String() string { return proto.CompactTextString(m) } +func (*LoginRequest) ProtoMessage() {} +func (*LoginRequest) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{0} } + +type LoginResponse struct { + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` +} + +func (m *LoginResponse) Reset() { *m = LoginResponse{} } +func (m *LoginResponse) String() string { return proto.CompactTextString(m) } +func (*LoginResponse) ProtoMessage() {} +func (*LoginResponse) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{1} } + +type LogoutRequest struct { + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` +} + +func (m *LogoutRequest) Reset() { *m = LogoutRequest{} } +func (m *LogoutRequest) String() string { return proto.CompactTextString(m) } +func (*LogoutRequest) ProtoMessage() {} +func (*LogoutRequest) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{2} } + +type LogoutResponse struct { + ErrMsg string `protobuf:"bytes,1,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` +} + +func (m *LogoutResponse) Reset() { *m = LogoutResponse{} } +func (m *LogoutResponse) String() string { return proto.CompactTextString(m) } +func (*LogoutResponse) ProtoMessage() {} +func (*LogoutResponse) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{3} } + +func init() { + proto.RegisterType((*LoginRequest)(nil), "session.LoginRequest") + proto.RegisterType((*LoginResponse)(nil), "session.LoginResponse") + proto.RegisterType((*LogoutRequest)(nil), "session.LogoutRequest") + proto.RegisterType((*LogoutResponse)(nil), "session.LogoutResponse") +} + +func init() { proto.RegisterFile("services/session/session.proto", fileDescriptorSession) } + +var fileDescriptorSession = []byte{ + // 231 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x6c, 0x50, 0xcb, 0x4a, 0xc5, 0x30, + 0x10, 0x35, 0xc2, 0xed, 0xd5, 0x41, 0xef, 0x62, 0x50, 0x6f, 0xe9, 0x42, 0x24, 0x20, 0xe8, 0xa6, + 0x82, 0x6e, 0x04, 0xc1, 0xa5, 0x2b, 0xdd, 0xb4, 0x1f, 0x20, 0x55, 0x87, 0x52, 0xa4, 0x99, 0x3a, + 0x93, 0xea, 0x27, 0xf8, 0xdb, 0x62, 0x93, 0x68, 0x7d, 0xac, 0xc2, 0xc9, 0xcc, 0x79, 0xcc, 0x81, + 0x43, 0x25, 0x79, 0xed, 0x1e, 0x49, 0xcf, 0x94, 0x54, 0x3b, 0x76, 0xe9, 0x2d, 0x07, 0x61, 0xcf, + 0xb8, 0x8c, 0xd0, 0xde, 0xc0, 0xce, 0x2d, 0xb7, 0x9d, 0xab, 0xe8, 0x65, 0x24, 0xf5, 0x58, 0xc0, + 0xd6, 0xa8, 0x24, 0xae, 0xe9, 0x29, 0x37, 0x47, 0xe6, 0x64, 0xbb, 0xfa, 0xc2, 0x9f, 0xb3, 0xa1, + 0x51, 0x7d, 0x63, 0x79, 0xca, 0x37, 0xc3, 0x2c, 0x61, 0x7b, 0x0d, 0xbb, 0x51, 0x47, 0x07, 0x76, + 0x4a, 0xb8, 0x07, 0x0b, 0xcf, 0xcf, 0xe4, 0xa2, 0x4a, 0x00, 0xb8, 0x86, 0x25, 0x89, 0xdc, 0xf7, + 0xda, 0x46, 0x85, 0x8c, 0x44, 0xee, 0xb4, 0xb5, 0xc7, 0x13, 0x9f, 0x47, 0x9f, 0x82, 0xfc, 0xcb, + 0xb7, 0xa7, 0xb0, 0x4a, 0x6b, 0xd1, 0x67, 0xa6, 0x68, 0xe6, 0x8a, 0xe7, 0xef, 0x06, 0x56, 0x75, + 0xb8, 0xb2, 0x0e, 0x65, 0xe0, 0x25, 0x2c, 0xa6, 0x90, 0xb8, 0x5f, 0xa6, 0x3a, 0xe6, 0xc7, 0x17, + 0x07, 0xbf, 0xbf, 0x83, 0x87, 0xdd, 0xc0, 0x2b, 0xc8, 0x82, 0x2f, 0xfe, 0xd8, 0xf9, 0xce, 0x5b, + 0xac, 0xff, 0xfc, 0x27, 0xf2, 0x43, 0x36, 0x75, 0x7e, 0xf1, 0x11, 0x00, 0x00, 0xff, 0xff, 0xc7, + 0x91, 0x50, 0x79, 0x95, 0x01, 0x00, 0x00, +} diff --git a/examples/go-kit/services/session/session.proto b/examples/go-kit/services/session/session.proto index 7935967..55f78a9 100644 --- a/examples/go-kit/services/session/session.proto +++ b/examples/go-kit/services/session/session.proto @@ -1,4 +1,4 @@ -syntax "proto3"; +syntax = "proto3"; package session; diff --git a/examples/go-kit/services/sprint/services/sprint/sprint.pb.go b/examples/go-kit/services/sprint/services/sprint/sprint.pb.go new file mode 100644 index 0000000..3246810 --- /dev/null +++ b/examples/go-kit/services/sprint/services/sprint/sprint.pb.go @@ -0,0 +1,151 @@ +// Code generated by protoc-gen-gogo. +// source: services/sprint/sprint.proto +// DO NOT EDIT! + +/* +Package sprint is a generated protocol buffer package. + +It is generated from these files: + services/sprint/sprint.proto + +It has these top-level messages: + AddSprintRequest + AddSprintResponse + CloseSprintRequest + CloseSprintResponse + GetSprintRequest + GetSprintResponse + Sprint +*/ +package sprint + +import proto "github.com/gogo/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 + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package + +type AddSprintRequest struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (m *AddSprintRequest) Reset() { *m = AddSprintRequest{} } +func (m *AddSprintRequest) String() string { return proto.CompactTextString(m) } +func (*AddSprintRequest) ProtoMessage() {} +func (*AddSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{0} } + +type AddSprintResponse struct { + Sprint *Sprint `protobuf:"bytes,1,opt,name=sprint" json:"sprint,omitempty"` + ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` +} + +func (m *AddSprintResponse) Reset() { *m = AddSprintResponse{} } +func (m *AddSprintResponse) String() string { return proto.CompactTextString(m) } +func (*AddSprintResponse) ProtoMessage() {} +func (*AddSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{1} } + +func (m *AddSprintResponse) GetSprint() *Sprint { + if m != nil { + return m.Sprint + } + return nil +} + +type CloseSprintRequest struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (m *CloseSprintRequest) Reset() { *m = CloseSprintRequest{} } +func (m *CloseSprintRequest) String() string { return proto.CompactTextString(m) } +func (*CloseSprintRequest) ProtoMessage() {} +func (*CloseSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{2} } + +type CloseSprintResponse struct { + ErrMsg string `protobuf:"bytes,1,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` +} + +func (m *CloseSprintResponse) Reset() { *m = CloseSprintResponse{} } +func (m *CloseSprintResponse) String() string { return proto.CompactTextString(m) } +func (*CloseSprintResponse) ProtoMessage() {} +func (*CloseSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{3} } + +type GetSprintRequest struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (m *GetSprintRequest) Reset() { *m = GetSprintRequest{} } +func (m *GetSprintRequest) String() string { return proto.CompactTextString(m) } +func (*GetSprintRequest) ProtoMessage() {} +func (*GetSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{4} } + +type GetSprintResponse struct { + Sprint *Sprint `protobuf:"bytes,1,opt,name=sprint" json:"sprint,omitempty"` + ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` +} + +func (m *GetSprintResponse) Reset() { *m = GetSprintResponse{} } +func (m *GetSprintResponse) String() string { return proto.CompactTextString(m) } +func (*GetSprintResponse) ProtoMessage() {} +func (*GetSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{5} } + +func (m *GetSprintResponse) GetSprint() *Sprint { + if m != nil { + return m.Sprint + } + return nil +} + +type Sprint struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + CreatedAt uint32 `protobuf:"varint,2,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` + Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` +} + +func (m *Sprint) Reset() { *m = Sprint{} } +func (m *Sprint) String() string { return proto.CompactTextString(m) } +func (*Sprint) ProtoMessage() {} +func (*Sprint) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{6} } + +func init() { + proto.RegisterType((*AddSprintRequest)(nil), "sprint.AddSprintRequest") + proto.RegisterType((*AddSprintResponse)(nil), "sprint.AddSprintResponse") + proto.RegisterType((*CloseSprintRequest)(nil), "sprint.CloseSprintRequest") + proto.RegisterType((*CloseSprintResponse)(nil), "sprint.CloseSprintResponse") + proto.RegisterType((*GetSprintRequest)(nil), "sprint.GetSprintRequest") + proto.RegisterType((*GetSprintResponse)(nil), "sprint.GetSprintResponse") + proto.RegisterType((*Sprint)(nil), "sprint.Sprint") +} + +func init() { proto.RegisterFile("services/sprint/sprint.proto", fileDescriptorSprint) } + +var fileDescriptorSprint = []byte{ + // 290 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xac, 0x52, 0x4d, 0x4b, 0xc3, 0x40, + 0x10, 0x6d, 0xaa, 0x44, 0x32, 0xa5, 0xa5, 0x1d, 0x0f, 0xc6, 0xa8, 0x20, 0x8b, 0x14, 0x4f, 0x11, + 0xea, 0x2f, 0x68, 0x3d, 0x28, 0x88, 0x97, 0xb4, 0xf7, 0x12, 0xbb, 0x43, 0x09, 0xd8, 0x24, 0xee, + 0xac, 0xfe, 0x5f, 0xff, 0x89, 0xb0, 0xbb, 0xcd, 0x57, 0x8b, 0x27, 0x4f, 0xc9, 0xec, 0xbc, 0x7d, + 0x6f, 0xe6, 0xbd, 0x85, 0x6b, 0x26, 0xf5, 0x9d, 0x6d, 0x88, 0x1f, 0xb8, 0x54, 0x59, 0xae, 0xdd, + 0x27, 0x2e, 0x55, 0xa1, 0x0b, 0xf4, 0x6d, 0x25, 0xa6, 0x30, 0x9e, 0x4b, 0xb9, 0x34, 0x45, 0x42, + 0x9f, 0x5f, 0xc4, 0x1a, 0x11, 0x4e, 0xf3, 0x74, 0x47, 0xa1, 0x77, 0xeb, 0xdd, 0x07, 0x89, 0xf9, + 0x17, 0x2b, 0x98, 0x34, 0x70, 0x5c, 0x16, 0x39, 0x13, 0x4e, 0xc1, 0xd1, 0x18, 0xe8, 0x60, 0x36, + 0x8a, 0x9d, 0x86, 0xc3, 0xb9, 0x2e, 0x5e, 0xc0, 0x19, 0x29, 0xb5, 0xde, 0xf1, 0x36, 0xec, 0x1b, + 0x4e, 0x9f, 0x94, 0x7a, 0xe3, 0xad, 0xb8, 0x03, 0x7c, 0xfa, 0x28, 0x98, 0xda, 0xfa, 0x23, 0xe8, + 0x67, 0xd2, 0xa9, 0xf7, 0x33, 0x29, 0x62, 0x38, 0x6f, 0xa1, 0x9c, 0x7a, 0x83, 0xd5, 0x6b, 0xb1, + 0x0a, 0x18, 0x3f, 0x93, 0xfe, 0x9b, 0x73, 0x05, 0x93, 0x06, 0xe6, 0xbf, 0xf6, 0x79, 0x05, 0xdf, + 0x42, 0xbb, 0x7a, 0x78, 0x03, 0xb0, 0x51, 0x94, 0x6a, 0x92, 0xeb, 0x54, 0x9b, 0x5b, 0xc3, 0x24, + 0x70, 0x27, 0xf3, 0xda, 0xf2, 0x93, 0xda, 0xf2, 0xd9, 0x8f, 0x07, 0x43, 0xcb, 0xb6, 0xb4, 0x49, + 0xe2, 0x02, 0x82, 0x2a, 0x04, 0x0c, 0xf7, 0xc3, 0x75, 0xf3, 0x8b, 0x2e, 0x8f, 0x74, 0xec, 0x86, + 0xa2, 0x87, 0x2f, 0x30, 0x68, 0x98, 0x89, 0xd1, 0x1e, 0x7b, 0x98, 0x43, 0x74, 0x75, 0xb4, 0x57, + 0x31, 0x2d, 0x20, 0xa8, 0x2c, 0xac, 0xa7, 0xe9, 0x3a, 0x5f, 0x4f, 0x73, 0xe0, 0xb7, 0xe8, 0xbd, + 0xfb, 0xe6, 0x35, 0x3e, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x9e, 0xb2, 0x1e, 0xad, 0x02, + 0x00, 0x00, +} diff --git a/examples/go-kit/services/sprint/sprint.proto b/examples/go-kit/services/sprint/sprint.proto index 001daad..dfb6a33 100644 --- a/examples/go-kit/services/sprint/sprint.proto +++ b/examples/go-kit/services/sprint/sprint.proto @@ -1,11 +1,11 @@ -syntax "proto3"; +syntax = "proto3"; package sprint; service SprintService { - rpc AddSprint(AddSprintRequest) returns AddSprintResponse {} - rpc CloseSprint(CloseSprintRequest) returns CloseSprintResponse {} - rpc GetSprint(GetSprintRequest) returns GetSprintResponse {} + rpc AddSprint(AddSprintRequest) returns (AddSprintResponse) {} + rpc CloseSprint(CloseSprintRequest) returns (CloseSprintResponse) {} + rpc GetSprint(GetSprintRequest) returns (GetSprintResponse) {} } message AddSprintRequest { From 71fb53ae02e4dca93e9ef1cc268a8fcf45e7a12f Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Tue, 13 Dec 2016 10:59:34 +0100 Subject: [PATCH 3/7] Add templates --- examples/go-kit/Makefile | 5 +- .../output/services/session/session.pb.go | 98 ------------ .../output/services/sprint/sprint.pb.go | 151 ------------------ .../{{.File.Package}}/gen/README.md.tmpl | 0 .../gen/client/client.go.tmpl | 1 + .../gen/cmd/{{.File.Package}}/main.go.tmpl | 1 + .../gen/endpoints/endpoints.go.tmpl | 1 + .../{{.File.Package}}/gen/init/init.go.tmpl | 1 + .../gen/transports/grpc/grpc.go.tmpl | 1 + .../gen/transports/http/http.go.tmpl | 1 + 10 files changed, 9 insertions(+), 251 deletions(-) delete mode 100644 examples/go-kit/output/services/session/session.pb.go delete mode 100644 examples/go-kit/output/services/sprint/sprint.pb.go create mode 100644 examples/go-kit/templates/{{.File.Package}}/gen/README.md.tmpl create mode 100644 examples/go-kit/templates/{{.File.Package}}/gen/client/client.go.tmpl create mode 100644 examples/go-kit/templates/{{.File.Package}}/gen/cmd/{{.File.Package}}/main.go.tmpl create mode 100644 examples/go-kit/templates/{{.File.Package}}/gen/endpoints/endpoints.go.tmpl create mode 100644 examples/go-kit/templates/{{.File.Package}}/gen/init/init.go.tmpl create mode 100644 examples/go-kit/templates/{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl create mode 100644 examples/go-kit/templates/{{.File.Package}}/gen/transports/http/http.go.tmpl diff --git a/examples/go-kit/Makefile b/examples/go-kit/Makefile index a9ffa0d..6cb08f1 100644 --- a/examples/go-kit/Makefile +++ b/examples/go-kit/Makefile @@ -7,8 +7,9 @@ TARGETS_TMPL := $(foreach source, $(SOURCES), $(source)_tmpl) build: $(TARGETS_GO) $(TARGETS_TMPL) $(TARGETS_GO): %_go: - protoc --gogo_out="$(dir $*)" "$*" + protoc --gogo_out=. "$*" $(TARGETS_TMPL): %_tmpl: @mkdir -p $(dir $*)gen - protoc -I. --gotemplate_out=template_dir=templates:output "$*" + protoc -I. --gotemplate_out=template_dir=templates:services "$*" + gofmt -w $(dir $*)gen diff --git a/examples/go-kit/output/services/session/session.pb.go b/examples/go-kit/output/services/session/session.pb.go deleted file mode 100644 index ca98145..0000000 --- a/examples/go-kit/output/services/session/session.pb.go +++ /dev/null @@ -1,98 +0,0 @@ -// Code generated by protoc-gen-go. -// source: services/session/session.proto -// DO NOT EDIT! - -/* -Package session is a generated protocol buffer package. - -It is generated from these files: - services/session/session.proto - -It has these top-level messages: - LoginRequest - LoginResponse - LogoutRequest - LogoutResponse -*/ -package session - -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 - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type LoginRequest struct { - Username string `protobuf:"bytes,1,opt,name=username" json:"username,omitempty"` - Password string `protobuf:"bytes,2,opt,name=password" json:"password,omitempty"` -} - -func (m *LoginRequest) Reset() { *m = LoginRequest{} } -func (m *LoginRequest) String() string { return proto.CompactTextString(m) } -func (*LoginRequest) ProtoMessage() {} -func (*LoginRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } - -type LoginResponse struct { - Token string `protobuf:"bytes,1,opt,name=token" json:"token,omitempty"` - ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg" json:"err_msg,omitempty"` -} - -func (m *LoginResponse) Reset() { *m = LoginResponse{} } -func (m *LoginResponse) String() string { return proto.CompactTextString(m) } -func (*LoginResponse) ProtoMessage() {} -func (*LoginResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } - -type LogoutRequest struct { - Token string `protobuf:"bytes,1,opt,name=token" json:"token,omitempty"` -} - -func (m *LogoutRequest) Reset() { *m = LogoutRequest{} } -func (m *LogoutRequest) String() string { return proto.CompactTextString(m) } -func (*LogoutRequest) ProtoMessage() {} -func (*LogoutRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } - -type LogoutResponse struct { - ErrMsg string `protobuf:"bytes,1,opt,name=err_msg,json=errMsg" json:"err_msg,omitempty"` -} - -func (m *LogoutResponse) Reset() { *m = LogoutResponse{} } -func (m *LogoutResponse) String() string { return proto.CompactTextString(m) } -func (*LogoutResponse) ProtoMessage() {} -func (*LogoutResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } - -func init() { - proto.RegisterType((*LoginRequest)(nil), "session.LoginRequest") - proto.RegisterType((*LoginResponse)(nil), "session.LoginResponse") - proto.RegisterType((*LogoutRequest)(nil), "session.LogoutRequest") - proto.RegisterType((*LogoutResponse)(nil), "session.LogoutResponse") -} - -func init() { proto.RegisterFile("services/session/session.proto", fileDescriptor0) } - -var fileDescriptor0 = []byte{ - // 231 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x6c, 0x50, 0xcb, 0x4a, 0xc5, 0x30, - 0x10, 0x35, 0xc2, 0xed, 0xd5, 0x41, 0xef, 0x62, 0x50, 0x6f, 0xe9, 0x42, 0x24, 0x20, 0xe8, 0xa6, - 0x82, 0x6e, 0x04, 0xc1, 0xa5, 0x2b, 0xdd, 0xb4, 0x1f, 0x20, 0x55, 0x87, 0x52, 0xa4, 0x99, 0x3a, - 0x93, 0xea, 0x27, 0xf8, 0xdb, 0x62, 0x93, 0x68, 0x7d, 0xac, 0xc2, 0xc9, 0xcc, 0x79, 0xcc, 0x81, - 0x43, 0x25, 0x79, 0xed, 0x1e, 0x49, 0xcf, 0x94, 0x54, 0x3b, 0x76, 0xe9, 0x2d, 0x07, 0x61, 0xcf, - 0xb8, 0x8c, 0xd0, 0xde, 0xc0, 0xce, 0x2d, 0xb7, 0x9d, 0xab, 0xe8, 0x65, 0x24, 0xf5, 0x58, 0xc0, - 0xd6, 0xa8, 0x24, 0xae, 0xe9, 0x29, 0x37, 0x47, 0xe6, 0x64, 0xbb, 0xfa, 0xc2, 0x9f, 0xb3, 0xa1, - 0x51, 0x7d, 0x63, 0x79, 0xca, 0x37, 0xc3, 0x2c, 0x61, 0x7b, 0x0d, 0xbb, 0x51, 0x47, 0x07, 0x76, - 0x4a, 0xb8, 0x07, 0x0b, 0xcf, 0xcf, 0xe4, 0xa2, 0x4a, 0x00, 0xb8, 0x86, 0x25, 0x89, 0xdc, 0xf7, - 0xda, 0x46, 0x85, 0x8c, 0x44, 0xee, 0xb4, 0xb5, 0xc7, 0x13, 0x9f, 0x47, 0x9f, 0x82, 0xfc, 0xcb, - 0xb7, 0xa7, 0xb0, 0x4a, 0x6b, 0xd1, 0x67, 0xa6, 0x68, 0xe6, 0x8a, 0xe7, 0xef, 0x06, 0x56, 0x75, - 0xb8, 0xb2, 0x0e, 0x65, 0xe0, 0x25, 0x2c, 0xa6, 0x90, 0xb8, 0x5f, 0xa6, 0x3a, 0xe6, 0xc7, 0x17, - 0x07, 0xbf, 0xbf, 0x83, 0x87, 0xdd, 0xc0, 0x2b, 0xc8, 0x82, 0x2f, 0xfe, 0xd8, 0xf9, 0xce, 0x5b, - 0xac, 0xff, 0xfc, 0x27, 0xf2, 0x43, 0x36, 0x75, 0x7e, 0xf1, 0x11, 0x00, 0x00, 0xff, 0xff, 0xc7, - 0x91, 0x50, 0x79, 0x95, 0x01, 0x00, 0x00, -} diff --git a/examples/go-kit/output/services/sprint/sprint.pb.go b/examples/go-kit/output/services/sprint/sprint.pb.go deleted file mode 100644 index 41ccefe..0000000 --- a/examples/go-kit/output/services/sprint/sprint.pb.go +++ /dev/null @@ -1,151 +0,0 @@ -// Code generated by protoc-gen-go. -// source: services/sprint/sprint.proto -// DO NOT EDIT! - -/* -Package sprint is a generated protocol buffer package. - -It is generated from these files: - services/sprint/sprint.proto - -It has these top-level messages: - AddSprintRequest - AddSprintResponse - CloseSprintRequest - CloseSprintResponse - GetSprintRequest - GetSprintResponse - Sprint -*/ -package sprint - -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 - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type AddSprintRequest struct { - Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` -} - -func (m *AddSprintRequest) Reset() { *m = AddSprintRequest{} } -func (m *AddSprintRequest) String() string { return proto.CompactTextString(m) } -func (*AddSprintRequest) ProtoMessage() {} -func (*AddSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } - -type AddSprintResponse struct { - Sprint *Sprint `protobuf:"bytes,1,opt,name=sprint" json:"sprint,omitempty"` - ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg" json:"err_msg,omitempty"` -} - -func (m *AddSprintResponse) Reset() { *m = AddSprintResponse{} } -func (m *AddSprintResponse) String() string { return proto.CompactTextString(m) } -func (*AddSprintResponse) ProtoMessage() {} -func (*AddSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } - -func (m *AddSprintResponse) GetSprint() *Sprint { - if m != nil { - return m.Sprint - } - return nil -} - -type CloseSprintRequest struct { - Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` -} - -func (m *CloseSprintRequest) Reset() { *m = CloseSprintRequest{} } -func (m *CloseSprintRequest) String() string { return proto.CompactTextString(m) } -func (*CloseSprintRequest) ProtoMessage() {} -func (*CloseSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } - -type CloseSprintResponse struct { - ErrMsg string `protobuf:"bytes,1,opt,name=err_msg,json=errMsg" json:"err_msg,omitempty"` -} - -func (m *CloseSprintResponse) Reset() { *m = CloseSprintResponse{} } -func (m *CloseSprintResponse) String() string { return proto.CompactTextString(m) } -func (*CloseSprintResponse) ProtoMessage() {} -func (*CloseSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } - -type GetSprintRequest struct { - Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` -} - -func (m *GetSprintRequest) Reset() { *m = GetSprintRequest{} } -func (m *GetSprintRequest) String() string { return proto.CompactTextString(m) } -func (*GetSprintRequest) ProtoMessage() {} -func (*GetSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} } - -type GetSprintResponse struct { - Sprint *Sprint `protobuf:"bytes,1,opt,name=sprint" json:"sprint,omitempty"` - ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg" json:"err_msg,omitempty"` -} - -func (m *GetSprintResponse) Reset() { *m = GetSprintResponse{} } -func (m *GetSprintResponse) String() string { return proto.CompactTextString(m) } -func (*GetSprintResponse) ProtoMessage() {} -func (*GetSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} } - -func (m *GetSprintResponse) GetSprint() *Sprint { - if m != nil { - return m.Sprint - } - return nil -} - -type Sprint struct { - Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` - CreatedAt uint32 `protobuf:"varint,2,opt,name=created_at,json=createdAt" json:"created_at,omitempty"` - Name string `protobuf:"bytes,3,opt,name=name" json:"name,omitempty"` -} - -func (m *Sprint) Reset() { *m = Sprint{} } -func (m *Sprint) String() string { return proto.CompactTextString(m) } -func (*Sprint) ProtoMessage() {} -func (*Sprint) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} } - -func init() { - proto.RegisterType((*AddSprintRequest)(nil), "sprint.AddSprintRequest") - proto.RegisterType((*AddSprintResponse)(nil), "sprint.AddSprintResponse") - proto.RegisterType((*CloseSprintRequest)(nil), "sprint.CloseSprintRequest") - proto.RegisterType((*CloseSprintResponse)(nil), "sprint.CloseSprintResponse") - proto.RegisterType((*GetSprintRequest)(nil), "sprint.GetSprintRequest") - proto.RegisterType((*GetSprintResponse)(nil), "sprint.GetSprintResponse") - proto.RegisterType((*Sprint)(nil), "sprint.Sprint") -} - -func init() { proto.RegisterFile("services/sprint/sprint.proto", fileDescriptor0) } - -var fileDescriptor0 = []byte{ - // 290 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xac, 0x52, 0x4d, 0x4b, 0xc3, 0x40, - 0x10, 0x6d, 0xaa, 0x44, 0x32, 0xa5, 0xa5, 0x1d, 0x0f, 0xc6, 0xa8, 0x20, 0x8b, 0x14, 0x4f, 0x11, - 0xea, 0x2f, 0x68, 0x3d, 0x28, 0x88, 0x97, 0xb4, 0xf7, 0x12, 0xbb, 0x43, 0x09, 0xd8, 0x24, 0xee, - 0xac, 0xfe, 0x5f, 0xff, 0x89, 0xb0, 0xbb, 0xcd, 0x57, 0x8b, 0x27, 0x4f, 0xc9, 0xec, 0xbc, 0x7d, - 0x6f, 0xe6, 0xbd, 0x85, 0x6b, 0x26, 0xf5, 0x9d, 0x6d, 0x88, 0x1f, 0xb8, 0x54, 0x59, 0xae, 0xdd, - 0x27, 0x2e, 0x55, 0xa1, 0x0b, 0xf4, 0x6d, 0x25, 0xa6, 0x30, 0x9e, 0x4b, 0xb9, 0x34, 0x45, 0x42, - 0x9f, 0x5f, 0xc4, 0x1a, 0x11, 0x4e, 0xf3, 0x74, 0x47, 0xa1, 0x77, 0xeb, 0xdd, 0x07, 0x89, 0xf9, - 0x17, 0x2b, 0x98, 0x34, 0x70, 0x5c, 0x16, 0x39, 0x13, 0x4e, 0xc1, 0xd1, 0x18, 0xe8, 0x60, 0x36, - 0x8a, 0x9d, 0x86, 0xc3, 0xb9, 0x2e, 0x5e, 0xc0, 0x19, 0x29, 0xb5, 0xde, 0xf1, 0x36, 0xec, 0x1b, - 0x4e, 0x9f, 0x94, 0x7a, 0xe3, 0xad, 0xb8, 0x03, 0x7c, 0xfa, 0x28, 0x98, 0xda, 0xfa, 0x23, 0xe8, - 0x67, 0xd2, 0xa9, 0xf7, 0x33, 0x29, 0x62, 0x38, 0x6f, 0xa1, 0x9c, 0x7a, 0x83, 0xd5, 0x6b, 0xb1, - 0x0a, 0x18, 0x3f, 0x93, 0xfe, 0x9b, 0x73, 0x05, 0x93, 0x06, 0xe6, 0xbf, 0xf6, 0x79, 0x05, 0xdf, - 0x42, 0xbb, 0x7a, 0x78, 0x03, 0xb0, 0x51, 0x94, 0x6a, 0x92, 0xeb, 0x54, 0x9b, 0x5b, 0xc3, 0x24, - 0x70, 0x27, 0xf3, 0xda, 0xf2, 0x93, 0xda, 0xf2, 0xd9, 0x8f, 0x07, 0x43, 0xcb, 0xb6, 0xb4, 0x49, - 0xe2, 0x02, 0x82, 0x2a, 0x04, 0x0c, 0xf7, 0xc3, 0x75, 0xf3, 0x8b, 0x2e, 0x8f, 0x74, 0xec, 0x86, - 0xa2, 0x87, 0x2f, 0x30, 0x68, 0x98, 0x89, 0xd1, 0x1e, 0x7b, 0x98, 0x43, 0x74, 0x75, 0xb4, 0x57, - 0x31, 0x2d, 0x20, 0xa8, 0x2c, 0xac, 0xa7, 0xe9, 0x3a, 0x5f, 0x4f, 0x73, 0xe0, 0xb7, 0xe8, 0xbd, - 0xfb, 0xe6, 0x35, 0x3e, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x9e, 0xb2, 0x1e, 0xad, 0x02, - 0x00, 0x00, -} diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/README.md.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/README.md.tmpl new file mode 100644 index 0000000..e69de29 diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/client/client.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/client/client.go.tmpl new file mode 100644 index 0000000..361fda1 --- /dev/null +++ b/examples/go-kit/templates/{{.File.Package}}/gen/client/client.go.tmpl @@ -0,0 +1 @@ +package {{.File.Package}}_client \ No newline at end of file diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/cmd/{{.File.Package}}/main.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/cmd/{{.File.Package}}/main.go.tmpl new file mode 100644 index 0000000..85f0393 --- /dev/null +++ b/examples/go-kit/templates/{{.File.Package}}/gen/cmd/{{.File.Package}}/main.go.tmpl @@ -0,0 +1 @@ +package main \ No newline at end of file diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/endpoints/endpoints.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/endpoints/endpoints.go.tmpl new file mode 100644 index 0000000..0189f91 --- /dev/null +++ b/examples/go-kit/templates/{{.File.Package}}/gen/endpoints/endpoints.go.tmpl @@ -0,0 +1 @@ +package {{.File.Package}}_endpoints \ No newline at end of file diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/init/init.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/init/init.go.tmpl new file mode 100644 index 0000000..176248c --- /dev/null +++ b/examples/go-kit/templates/{{.File.Package}}/gen/init/init.go.tmpl @@ -0,0 +1 @@ +package {{.File.Package}}_init \ No newline at end of file diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl new file mode 100644 index 0000000..9b86de9 --- /dev/null +++ b/examples/go-kit/templates/{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl @@ -0,0 +1 @@ +package {{.File.Package}}_transportgrpc \ No newline at end of file diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/transports/http/http.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/transports/http/http.go.tmpl new file mode 100644 index 0000000..ff0559d --- /dev/null +++ b/examples/go-kit/templates/{{.File.Package}}/gen/transports/http/http.go.tmpl @@ -0,0 +1 @@ +package {{.File.Package}}_transporthttp \ No newline at end of file From bffc245a82fc60261e752a868a1a43d75f690ed0 Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Tue, 13 Dec 2016 11:05:06 +0100 Subject: [PATCH 4/7] generate services boilerplate code --- examples/go-kit/Makefile | 1 + .../go-kit/services/session/gen/README.md | 0 .../services/session/gen/client/client.go | 1 + .../services/session/gen/cmd/session/main.go | 1 + .../session/gen/endpoints/endpoints.go | 1 + .../go-kit/services/session/gen/init/init.go | 1 + .../session/gen/transports/grpc/grpc.go | 1 + .../session/gen/transports/http/http.go | 1 + .../go-kit/services/session/session.pb.go | 98 ++++++++++++ examples/go-kit/services/sprint/gen/README.md | 0 .../services/sprint/gen/client/client.go | 1 + .../services/sprint/gen/cmd/sprint/main.go | 1 + .../sprint/gen/endpoints/endpoints.go | 1 + .../go-kit/services/sprint/gen/init/init.go | 1 + .../sprint/gen/transports/grpc/grpc.go | 1 + .../sprint/gen/transports/http/http.go | 1 + examples/go-kit/services/sprint/sprint.pb.go | 151 ++++++++++++++++++ 17 files changed, 262 insertions(+) create mode 100644 examples/go-kit/services/session/gen/README.md create mode 100644 examples/go-kit/services/session/gen/client/client.go create mode 100644 examples/go-kit/services/session/gen/cmd/session/main.go create mode 100644 examples/go-kit/services/session/gen/endpoints/endpoints.go create mode 100644 examples/go-kit/services/session/gen/init/init.go create mode 100644 examples/go-kit/services/session/gen/transports/grpc/grpc.go create mode 100644 examples/go-kit/services/session/gen/transports/http/http.go create mode 100644 examples/go-kit/services/session/session.pb.go create mode 100644 examples/go-kit/services/sprint/gen/README.md create mode 100644 examples/go-kit/services/sprint/gen/client/client.go create mode 100644 examples/go-kit/services/sprint/gen/cmd/sprint/main.go create mode 100644 examples/go-kit/services/sprint/gen/endpoints/endpoints.go create mode 100644 examples/go-kit/services/sprint/gen/init/init.go create mode 100644 examples/go-kit/services/sprint/gen/transports/grpc/grpc.go create mode 100644 examples/go-kit/services/sprint/gen/transports/http/http.go create mode 100644 examples/go-kit/services/sprint/sprint.pb.go diff --git a/examples/go-kit/Makefile b/examples/go-kit/Makefile index 6cb08f1..69c6cec 100644 --- a/examples/go-kit/Makefile +++ b/examples/go-kit/Makefile @@ -12,4 +12,5 @@ $(TARGETS_GO): %_go: $(TARGETS_TMPL): %_tmpl: @mkdir -p $(dir $*)gen protoc -I. --gotemplate_out=template_dir=templates:services "$*" + @rm -rf services/services # need to investigate why this directory is created gofmt -w $(dir $*)gen diff --git a/examples/go-kit/services/session/gen/README.md b/examples/go-kit/services/session/gen/README.md new file mode 100644 index 0000000..e69de29 diff --git a/examples/go-kit/services/session/gen/client/client.go b/examples/go-kit/services/session/gen/client/client.go new file mode 100644 index 0000000..0122145 --- /dev/null +++ b/examples/go-kit/services/session/gen/client/client.go @@ -0,0 +1 @@ +package session_client diff --git a/examples/go-kit/services/session/gen/cmd/session/main.go b/examples/go-kit/services/session/gen/cmd/session/main.go new file mode 100644 index 0000000..06ab7d0 --- /dev/null +++ b/examples/go-kit/services/session/gen/cmd/session/main.go @@ -0,0 +1 @@ +package main diff --git a/examples/go-kit/services/session/gen/endpoints/endpoints.go b/examples/go-kit/services/session/gen/endpoints/endpoints.go new file mode 100644 index 0000000..3527a99 --- /dev/null +++ b/examples/go-kit/services/session/gen/endpoints/endpoints.go @@ -0,0 +1 @@ +package session_endpoints diff --git a/examples/go-kit/services/session/gen/init/init.go b/examples/go-kit/services/session/gen/init/init.go new file mode 100644 index 0000000..839df55 --- /dev/null +++ b/examples/go-kit/services/session/gen/init/init.go @@ -0,0 +1 @@ +package session_init diff --git a/examples/go-kit/services/session/gen/transports/grpc/grpc.go b/examples/go-kit/services/session/gen/transports/grpc/grpc.go new file mode 100644 index 0000000..4f94972 --- /dev/null +++ b/examples/go-kit/services/session/gen/transports/grpc/grpc.go @@ -0,0 +1 @@ +package session_transportgrpc diff --git a/examples/go-kit/services/session/gen/transports/http/http.go b/examples/go-kit/services/session/gen/transports/http/http.go new file mode 100644 index 0000000..9aab217 --- /dev/null +++ b/examples/go-kit/services/session/gen/transports/http/http.go @@ -0,0 +1 @@ +package session_transporthttp diff --git a/examples/go-kit/services/session/session.pb.go b/examples/go-kit/services/session/session.pb.go new file mode 100644 index 0000000..c07e0a0 --- /dev/null +++ b/examples/go-kit/services/session/session.pb.go @@ -0,0 +1,98 @@ +// Code generated by protoc-gen-gogo. +// source: services/session/session.proto +// DO NOT EDIT! + +/* +Package session is a generated protocol buffer package. + +It is generated from these files: + services/session/session.proto + +It has these top-level messages: + LoginRequest + LoginResponse + LogoutRequest + LogoutResponse +*/ +package session + +import proto "github.com/gogo/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 + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package + +type LoginRequest struct { + Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` + Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` +} + +func (m *LoginRequest) Reset() { *m = LoginRequest{} } +func (m *LoginRequest) String() string { return proto.CompactTextString(m) } +func (*LoginRequest) ProtoMessage() {} +func (*LoginRequest) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{0} } + +type LoginResponse struct { + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` +} + +func (m *LoginResponse) Reset() { *m = LoginResponse{} } +func (m *LoginResponse) String() string { return proto.CompactTextString(m) } +func (*LoginResponse) ProtoMessage() {} +func (*LoginResponse) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{1} } + +type LogoutRequest struct { + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` +} + +func (m *LogoutRequest) Reset() { *m = LogoutRequest{} } +func (m *LogoutRequest) String() string { return proto.CompactTextString(m) } +func (*LogoutRequest) ProtoMessage() {} +func (*LogoutRequest) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{2} } + +type LogoutResponse struct { + ErrMsg string `protobuf:"bytes,1,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` +} + +func (m *LogoutResponse) Reset() { *m = LogoutResponse{} } +func (m *LogoutResponse) String() string { return proto.CompactTextString(m) } +func (*LogoutResponse) ProtoMessage() {} +func (*LogoutResponse) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{3} } + +func init() { + proto.RegisterType((*LoginRequest)(nil), "session.LoginRequest") + proto.RegisterType((*LoginResponse)(nil), "session.LoginResponse") + proto.RegisterType((*LogoutRequest)(nil), "session.LogoutRequest") + proto.RegisterType((*LogoutResponse)(nil), "session.LogoutResponse") +} + +func init() { proto.RegisterFile("services/session/session.proto", fileDescriptorSession) } + +var fileDescriptorSession = []byte{ + // 231 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x6c, 0x50, 0xcb, 0x4a, 0xc5, 0x30, + 0x10, 0x35, 0xc2, 0xed, 0xd5, 0x41, 0xef, 0x62, 0x50, 0x6f, 0xe9, 0x42, 0x24, 0x20, 0xe8, 0xa6, + 0x82, 0x6e, 0x04, 0xc1, 0xa5, 0x2b, 0xdd, 0xb4, 0x1f, 0x20, 0x55, 0x87, 0x52, 0xa4, 0x99, 0x3a, + 0x93, 0xea, 0x27, 0xf8, 0xdb, 0x62, 0x93, 0x68, 0x7d, 0xac, 0xc2, 0xc9, 0xcc, 0x79, 0xcc, 0x81, + 0x43, 0x25, 0x79, 0xed, 0x1e, 0x49, 0xcf, 0x94, 0x54, 0x3b, 0x76, 0xe9, 0x2d, 0x07, 0x61, 0xcf, + 0xb8, 0x8c, 0xd0, 0xde, 0xc0, 0xce, 0x2d, 0xb7, 0x9d, 0xab, 0xe8, 0x65, 0x24, 0xf5, 0x58, 0xc0, + 0xd6, 0xa8, 0x24, 0xae, 0xe9, 0x29, 0x37, 0x47, 0xe6, 0x64, 0xbb, 0xfa, 0xc2, 0x9f, 0xb3, 0xa1, + 0x51, 0x7d, 0x63, 0x79, 0xca, 0x37, 0xc3, 0x2c, 0x61, 0x7b, 0x0d, 0xbb, 0x51, 0x47, 0x07, 0x76, + 0x4a, 0xb8, 0x07, 0x0b, 0xcf, 0xcf, 0xe4, 0xa2, 0x4a, 0x00, 0xb8, 0x86, 0x25, 0x89, 0xdc, 0xf7, + 0xda, 0x46, 0x85, 0x8c, 0x44, 0xee, 0xb4, 0xb5, 0xc7, 0x13, 0x9f, 0x47, 0x9f, 0x82, 0xfc, 0xcb, + 0xb7, 0xa7, 0xb0, 0x4a, 0x6b, 0xd1, 0x67, 0xa6, 0x68, 0xe6, 0x8a, 0xe7, 0xef, 0x06, 0x56, 0x75, + 0xb8, 0xb2, 0x0e, 0x65, 0xe0, 0x25, 0x2c, 0xa6, 0x90, 0xb8, 0x5f, 0xa6, 0x3a, 0xe6, 0xc7, 0x17, + 0x07, 0xbf, 0xbf, 0x83, 0x87, 0xdd, 0xc0, 0x2b, 0xc8, 0x82, 0x2f, 0xfe, 0xd8, 0xf9, 0xce, 0x5b, + 0xac, 0xff, 0xfc, 0x27, 0xf2, 0x43, 0x36, 0x75, 0x7e, 0xf1, 0x11, 0x00, 0x00, 0xff, 0xff, 0xc7, + 0x91, 0x50, 0x79, 0x95, 0x01, 0x00, 0x00, +} diff --git a/examples/go-kit/services/sprint/gen/README.md b/examples/go-kit/services/sprint/gen/README.md new file mode 100644 index 0000000..e69de29 diff --git a/examples/go-kit/services/sprint/gen/client/client.go b/examples/go-kit/services/sprint/gen/client/client.go new file mode 100644 index 0000000..452a32c --- /dev/null +++ b/examples/go-kit/services/sprint/gen/client/client.go @@ -0,0 +1 @@ +package sprint_client diff --git a/examples/go-kit/services/sprint/gen/cmd/sprint/main.go b/examples/go-kit/services/sprint/gen/cmd/sprint/main.go new file mode 100644 index 0000000..06ab7d0 --- /dev/null +++ b/examples/go-kit/services/sprint/gen/cmd/sprint/main.go @@ -0,0 +1 @@ +package main diff --git a/examples/go-kit/services/sprint/gen/endpoints/endpoints.go b/examples/go-kit/services/sprint/gen/endpoints/endpoints.go new file mode 100644 index 0000000..42fa1b6 --- /dev/null +++ b/examples/go-kit/services/sprint/gen/endpoints/endpoints.go @@ -0,0 +1 @@ +package sprint_endpoints diff --git a/examples/go-kit/services/sprint/gen/init/init.go b/examples/go-kit/services/sprint/gen/init/init.go new file mode 100644 index 0000000..4a970cc --- /dev/null +++ b/examples/go-kit/services/sprint/gen/init/init.go @@ -0,0 +1 @@ +package sprint_init diff --git a/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go b/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go new file mode 100644 index 0000000..aa115af --- /dev/null +++ b/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go @@ -0,0 +1 @@ +package sprint_transportgrpc diff --git a/examples/go-kit/services/sprint/gen/transports/http/http.go b/examples/go-kit/services/sprint/gen/transports/http/http.go new file mode 100644 index 0000000..540b97b --- /dev/null +++ b/examples/go-kit/services/sprint/gen/transports/http/http.go @@ -0,0 +1 @@ +package sprint_transporthttp diff --git a/examples/go-kit/services/sprint/sprint.pb.go b/examples/go-kit/services/sprint/sprint.pb.go new file mode 100644 index 0000000..3246810 --- /dev/null +++ b/examples/go-kit/services/sprint/sprint.pb.go @@ -0,0 +1,151 @@ +// Code generated by protoc-gen-gogo. +// source: services/sprint/sprint.proto +// DO NOT EDIT! + +/* +Package sprint is a generated protocol buffer package. + +It is generated from these files: + services/sprint/sprint.proto + +It has these top-level messages: + AddSprintRequest + AddSprintResponse + CloseSprintRequest + CloseSprintResponse + GetSprintRequest + GetSprintResponse + Sprint +*/ +package sprint + +import proto "github.com/gogo/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 + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package + +type AddSprintRequest struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (m *AddSprintRequest) Reset() { *m = AddSprintRequest{} } +func (m *AddSprintRequest) String() string { return proto.CompactTextString(m) } +func (*AddSprintRequest) ProtoMessage() {} +func (*AddSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{0} } + +type AddSprintResponse struct { + Sprint *Sprint `protobuf:"bytes,1,opt,name=sprint" json:"sprint,omitempty"` + ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` +} + +func (m *AddSprintResponse) Reset() { *m = AddSprintResponse{} } +func (m *AddSprintResponse) String() string { return proto.CompactTextString(m) } +func (*AddSprintResponse) ProtoMessage() {} +func (*AddSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{1} } + +func (m *AddSprintResponse) GetSprint() *Sprint { + if m != nil { + return m.Sprint + } + return nil +} + +type CloseSprintRequest struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (m *CloseSprintRequest) Reset() { *m = CloseSprintRequest{} } +func (m *CloseSprintRequest) String() string { return proto.CompactTextString(m) } +func (*CloseSprintRequest) ProtoMessage() {} +func (*CloseSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{2} } + +type CloseSprintResponse struct { + ErrMsg string `protobuf:"bytes,1,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` +} + +func (m *CloseSprintResponse) Reset() { *m = CloseSprintResponse{} } +func (m *CloseSprintResponse) String() string { return proto.CompactTextString(m) } +func (*CloseSprintResponse) ProtoMessage() {} +func (*CloseSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{3} } + +type GetSprintRequest struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (m *GetSprintRequest) Reset() { *m = GetSprintRequest{} } +func (m *GetSprintRequest) String() string { return proto.CompactTextString(m) } +func (*GetSprintRequest) ProtoMessage() {} +func (*GetSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{4} } + +type GetSprintResponse struct { + Sprint *Sprint `protobuf:"bytes,1,opt,name=sprint" json:"sprint,omitempty"` + ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` +} + +func (m *GetSprintResponse) Reset() { *m = GetSprintResponse{} } +func (m *GetSprintResponse) String() string { return proto.CompactTextString(m) } +func (*GetSprintResponse) ProtoMessage() {} +func (*GetSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{5} } + +func (m *GetSprintResponse) GetSprint() *Sprint { + if m != nil { + return m.Sprint + } + return nil +} + +type Sprint struct { + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + CreatedAt uint32 `protobuf:"varint,2,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` + Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` +} + +func (m *Sprint) Reset() { *m = Sprint{} } +func (m *Sprint) String() string { return proto.CompactTextString(m) } +func (*Sprint) ProtoMessage() {} +func (*Sprint) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{6} } + +func init() { + proto.RegisterType((*AddSprintRequest)(nil), "sprint.AddSprintRequest") + proto.RegisterType((*AddSprintResponse)(nil), "sprint.AddSprintResponse") + proto.RegisterType((*CloseSprintRequest)(nil), "sprint.CloseSprintRequest") + proto.RegisterType((*CloseSprintResponse)(nil), "sprint.CloseSprintResponse") + proto.RegisterType((*GetSprintRequest)(nil), "sprint.GetSprintRequest") + proto.RegisterType((*GetSprintResponse)(nil), "sprint.GetSprintResponse") + proto.RegisterType((*Sprint)(nil), "sprint.Sprint") +} + +func init() { proto.RegisterFile("services/sprint/sprint.proto", fileDescriptorSprint) } + +var fileDescriptorSprint = []byte{ + // 290 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xac, 0x52, 0x4d, 0x4b, 0xc3, 0x40, + 0x10, 0x6d, 0xaa, 0x44, 0x32, 0xa5, 0xa5, 0x1d, 0x0f, 0xc6, 0xa8, 0x20, 0x8b, 0x14, 0x4f, 0x11, + 0xea, 0x2f, 0x68, 0x3d, 0x28, 0x88, 0x97, 0xb4, 0xf7, 0x12, 0xbb, 0x43, 0x09, 0xd8, 0x24, 0xee, + 0xac, 0xfe, 0x5f, 0xff, 0x89, 0xb0, 0xbb, 0xcd, 0x57, 0x8b, 0x27, 0x4f, 0xc9, 0xec, 0xbc, 0x7d, + 0x6f, 0xe6, 0xbd, 0x85, 0x6b, 0x26, 0xf5, 0x9d, 0x6d, 0x88, 0x1f, 0xb8, 0x54, 0x59, 0xae, 0xdd, + 0x27, 0x2e, 0x55, 0xa1, 0x0b, 0xf4, 0x6d, 0x25, 0xa6, 0x30, 0x9e, 0x4b, 0xb9, 0x34, 0x45, 0x42, + 0x9f, 0x5f, 0xc4, 0x1a, 0x11, 0x4e, 0xf3, 0x74, 0x47, 0xa1, 0x77, 0xeb, 0xdd, 0x07, 0x89, 0xf9, + 0x17, 0x2b, 0x98, 0x34, 0x70, 0x5c, 0x16, 0x39, 0x13, 0x4e, 0xc1, 0xd1, 0x18, 0xe8, 0x60, 0x36, + 0x8a, 0x9d, 0x86, 0xc3, 0xb9, 0x2e, 0x5e, 0xc0, 0x19, 0x29, 0xb5, 0xde, 0xf1, 0x36, 0xec, 0x1b, + 0x4e, 0x9f, 0x94, 0x7a, 0xe3, 0xad, 0xb8, 0x03, 0x7c, 0xfa, 0x28, 0x98, 0xda, 0xfa, 0x23, 0xe8, + 0x67, 0xd2, 0xa9, 0xf7, 0x33, 0x29, 0x62, 0x38, 0x6f, 0xa1, 0x9c, 0x7a, 0x83, 0xd5, 0x6b, 0xb1, + 0x0a, 0x18, 0x3f, 0x93, 0xfe, 0x9b, 0x73, 0x05, 0x93, 0x06, 0xe6, 0xbf, 0xf6, 0x79, 0x05, 0xdf, + 0x42, 0xbb, 0x7a, 0x78, 0x03, 0xb0, 0x51, 0x94, 0x6a, 0x92, 0xeb, 0x54, 0x9b, 0x5b, 0xc3, 0x24, + 0x70, 0x27, 0xf3, 0xda, 0xf2, 0x93, 0xda, 0xf2, 0xd9, 0x8f, 0x07, 0x43, 0xcb, 0xb6, 0xb4, 0x49, + 0xe2, 0x02, 0x82, 0x2a, 0x04, 0x0c, 0xf7, 0xc3, 0x75, 0xf3, 0x8b, 0x2e, 0x8f, 0x74, 0xec, 0x86, + 0xa2, 0x87, 0x2f, 0x30, 0x68, 0x98, 0x89, 0xd1, 0x1e, 0x7b, 0x98, 0x43, 0x74, 0x75, 0xb4, 0x57, + 0x31, 0x2d, 0x20, 0xa8, 0x2c, 0xac, 0xa7, 0xe9, 0x3a, 0x5f, 0x4f, 0x73, 0xe0, 0xb7, 0xe8, 0xbd, + 0xfb, 0xe6, 0x35, 0x3e, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x9e, 0xb2, 0x1e, 0xad, 0x02, + 0x00, 0x00, +} From f62940ac4cdc2d7e5bb7b89e0ae3fa17b664af31 Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Tue, 13 Dec 2016 15:31:37 +0100 Subject: [PATCH 5/7] Generate endpoints + transports --- .../services/session/gen/client/client.go | 1 - .../services/session/gen/cmd/session/main.go | 1 - .../session/gen/endpoints/endpoints.go | 62 +++++++++++ .../go-kit/services/session/gen/init/init.go | 1 - .../session/gen/transports/grpc/grpc.go | 74 +++++++++++++ .../session/gen/transports/http/http.go | 67 ++++++++++++ .../services/sprint/gen/client/client.go | 1 - .../services/sprint/gen/cmd/sprint/main.go | 1 - .../sprint/gen/endpoints/endpoints.go | 85 +++++++++++++++ .../go-kit/services/sprint/gen/init/init.go | 1 - .../sprint/gen/transports/grpc/grpc.go | 101 ++++++++++++++++++ .../sprint/gen/transports/http/http.go | 92 ++++++++++++++++ .../gen/client/client.go.tmpl | 1 - .../gen/cmd/{{.File.Package}}/main.go.tmpl | 1 - .../gen/endpoints/endpoints.go.tmpl | 50 ++++++++- .../{{.File.Package}}/gen/init/init.go.tmpl | 1 - .../gen/transports/grpc/grpc.go.tmpl | 60 ++++++++++- .../gen/transports/http/http.go.tmpl | 48 ++++++++- 18 files changed, 636 insertions(+), 12 deletions(-) delete mode 100644 examples/go-kit/services/session/gen/client/client.go delete mode 100644 examples/go-kit/services/session/gen/cmd/session/main.go delete mode 100644 examples/go-kit/services/session/gen/init/init.go delete mode 100644 examples/go-kit/services/sprint/gen/client/client.go delete mode 100644 examples/go-kit/services/sprint/gen/cmd/sprint/main.go delete mode 100644 examples/go-kit/services/sprint/gen/init/init.go delete mode 100644 examples/go-kit/templates/{{.File.Package}}/gen/client/client.go.tmpl delete mode 100644 examples/go-kit/templates/{{.File.Package}}/gen/cmd/{{.File.Package}}/main.go.tmpl delete mode 100644 examples/go-kit/templates/{{.File.Package}}/gen/init/init.go.tmpl diff --git a/examples/go-kit/services/session/gen/client/client.go b/examples/go-kit/services/session/gen/client/client.go deleted file mode 100644 index 0122145..0000000 --- a/examples/go-kit/services/session/gen/client/client.go +++ /dev/null @@ -1 +0,0 @@ -package session_client diff --git a/examples/go-kit/services/session/gen/cmd/session/main.go b/examples/go-kit/services/session/gen/cmd/session/main.go deleted file mode 100644 index 06ab7d0..0000000 --- a/examples/go-kit/services/session/gen/cmd/session/main.go +++ /dev/null @@ -1 +0,0 @@ -package main diff --git a/examples/go-kit/services/session/gen/endpoints/endpoints.go b/examples/go-kit/services/session/gen/endpoints/endpoints.go index 3527a99..f64d456 100644 --- a/examples/go-kit/services/session/gen/endpoints/endpoints.go +++ b/examples/go-kit/services/session/gen/endpoints/endpoints.go @@ -1 +1,63 @@ package session_endpoints + +import ( + "fmt" + "github.com/go-kit/kit/endpoint" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session" + context "golang.org/x/net/context" +) + +var _ = fmt.Errorf + +type Endpoints struct { + LoginEndpoint endpoint.Endpoint + + LogoutEndpoint endpoint.Endpoint +} + +func (e *Endpoints) Login(ctx context.Context, in *pb.LoginRequest) (*pb.LoginResponse, error) { + out, err := e.LoginEndpoint(ctx, in) + if err != nil { + return &pb.LoginResponse{ErrMsg: err.Error()}, err + } + return out.(*pb.LoginReply), err +} + +func (e *Endpoints) Logout(ctx context.Context, in *pb.LogoutRequest) (*pb.LogoutResponse, error) { + out, err := e.LogoutEndpoint(ctx, in) + if err != nil { + return &pb.LogoutResponse{ErrMsg: err.Error()}, err + } + return out.(*pb.LogoutReply), err +} + +func MakeLoginEndpoint(svc pb.SessionServiceServer) endpoint.Endpoint { + return func(ctx context.Context, request interface{}) (interface{}, error) { + req := request.(*pb.LoginRequest) + rep, err := svc.Login(ctx, req) + if err != nil { + return &pb.LoginReply{ErrMsg: err.Error()}, err + } + return rep, nil + } +} + +func MakeLogoutEndpoint(svc pb.SessionServiceServer) endpoint.Endpoint { + return func(ctx context.Context, request interface{}) (interface{}, error) { + req := request.(*pb.LogoutRequest) + rep, err := svc.Logout(ctx, req) + if err != nil { + return &pb.LogoutReply{ErrMsg: err.Error()}, err + } + return rep, nil + } +} + +func MakeEndpoints(svc pb.SessionServiceServer) Endpoints { + return Endpoints{ + + LoginEndpoint: MakeLoginEndpoint(svc), + + LogoutEndpoint: MakeLogoutEndpoint(svc), + } +} diff --git a/examples/go-kit/services/session/gen/init/init.go b/examples/go-kit/services/session/gen/init/init.go deleted file mode 100644 index 839df55..0000000 --- a/examples/go-kit/services/session/gen/init/init.go +++ /dev/null @@ -1 +0,0 @@ -package session_init diff --git a/examples/go-kit/services/session/gen/transports/grpc/grpc.go b/examples/go-kit/services/session/gen/transports/grpc/grpc.go index 4f94972..4fce3bb 100644 --- a/examples/go-kit/services/session/gen/transports/grpc/grpc.go +++ b/examples/go-kit/services/session/gen/transports/grpc/grpc.go @@ -1 +1,75 @@ package session_transportgrpc + +import ( + "fmt" + + grpctransport "github.com/go-kit/kit/transport/grpc" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session" + endpoint "github.com/moul/protoc-gen-gotemplate/examples/go-kit/session/gen/endpoints" + context "golang.org/x/net/context" +) + +// avoid import errors +var _ = fmt.Errorf + +func MakeGRPCServer(ctx context.Context, endpoints endpoint.Endpoints) pb.SessionServiceServer { + options := []grpctransport.ServerOption{} + return &grpcServer{ + + login: grpctransport.NewServer( + ctx, + endpoints.LoginEndpoint, + decodeLoginRequest, + encodeLoginResponse, + options, + ), + + logout: grpctransport.NewServer( + ctx, + endpoints.LogoutEndpoint, + decodeLogoutRequest, + encodeLogoutResponse, + options, + ), + } +} + +type grpcServer struct { + login grpctransport.Handler + + logout grpctransport.Handler +} + +func (s *grpcServer) Login(ctx context.Context, req *pb.LoginRequest) (*pb.LoginReply, error) { + _, rep, err := s.login.ServeGRPC(ctx, req) + if err != nil { + return nil, err + } + return rep.(*pb.LoginReply), nil +} + +func decodeLoginRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) { + return grpcReq, nil +} + +func encodeLoginResponse(ctx context.Context, response interface{}) (interface{}, error) { + resp := response.(*pb.LoginReply) + return resp, nil +} + +func (s *grpcServer) Logout(ctx context.Context, req *pb.LogoutRequest) (*pb.LogoutReply, error) { + _, rep, err := s.logout.ServeGRPC(ctx, req) + if err != nil { + return nil, err + } + return rep.(*pb.LogoutReply), nil +} + +func decodeLogoutRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) { + return grpcReq, nil +} + +func encodeLogoutResponse(ctx context.Context, response interface{}) (interface{}, error) { + resp := response.(*pb.LogoutReply) + return resp, nil +} diff --git a/examples/go-kit/services/session/gen/transports/http/http.go b/examples/go-kit/services/session/gen/transports/http/http.go index 9aab217..842e4d0 100644 --- a/examples/go-kit/services/session/gen/transports/http/http.go +++ b/examples/go-kit/services/session/gen/transports/http/http.go @@ -1 +1,68 @@ package session_transporthttp + +import ( + "encoding/json" + context "golang.org/x/net/context" + "log" + "net/http" + + gokit_endpoint "github.com/go-kit/kit/endpoint" + httptransport "github.com/go-kit/kit/transport/http" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session" + endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/session/gen/endpoints" +) + +func MakeLoginHandler(ctx context.Context, svc pb.SessionServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server { + return httptransport.NewServer( + ctx, + endpoint, + decodeLoginRequest, + encodeLoginResponse, + append([]httptransport.ServerOption{}, httptransport.ServerBefore(jwt.ToHTTPContext()))..., + ) +} + +func decodeLoginRequest(ctx context.Context, r *http.Request) (interface{}, error) { + var req pb.LoginRequest + if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + return nil, err + } + return &req, nil +} + +func encodeLoginResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { + return json.NewEncoder(w).Encode(response) +} + +func MakeLogoutHandler(ctx context.Context, svc pb.SessionServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server { + return httptransport.NewServer( + ctx, + endpoint, + decodeLogoutRequest, + encodeLogoutResponse, + append([]httptransport.ServerOption{}, httptransport.ServerBefore(jwt.ToHTTPContext()))..., + ) +} + +func decodeLogoutRequest(ctx context.Context, r *http.Request) (interface{}, error) { + var req pb.LogoutRequest + if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + return nil, err + } + return &req, nil +} + +func encodeLogoutResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { + return json.NewEncoder(w).Encode(response) +} + +func RegisterHandlers(ctx context.Context, svc pb.SessionServiceServer, mux *http.ServeMux, endpoints endpoints.Endpoints) error { + + log.Println("new HTTP endpoint: \"/Login\" (service=Session)") + mux.Handle("/Login", MakeLoginHandler(ctx, svc, endpoints.LoginEndpoint)) + + log.Println("new HTTP endpoint: \"/Logout\" (service=Session)") + mux.Handle("/Logout", MakeLogoutHandler(ctx, svc, endpoints.LogoutEndpoint)) + + return nil +} diff --git a/examples/go-kit/services/sprint/gen/client/client.go b/examples/go-kit/services/sprint/gen/client/client.go deleted file mode 100644 index 452a32c..0000000 --- a/examples/go-kit/services/sprint/gen/client/client.go +++ /dev/null @@ -1 +0,0 @@ -package sprint_client diff --git a/examples/go-kit/services/sprint/gen/cmd/sprint/main.go b/examples/go-kit/services/sprint/gen/cmd/sprint/main.go deleted file mode 100644 index 06ab7d0..0000000 --- a/examples/go-kit/services/sprint/gen/cmd/sprint/main.go +++ /dev/null @@ -1 +0,0 @@ -package main diff --git a/examples/go-kit/services/sprint/gen/endpoints/endpoints.go b/examples/go-kit/services/sprint/gen/endpoints/endpoints.go index 42fa1b6..a58ff09 100644 --- a/examples/go-kit/services/sprint/gen/endpoints/endpoints.go +++ b/examples/go-kit/services/sprint/gen/endpoints/endpoints.go @@ -1 +1,86 @@ package sprint_endpoints + +import ( + "fmt" + "github.com/go-kit/kit/endpoint" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint" + context "golang.org/x/net/context" +) + +var _ = fmt.Errorf + +type Endpoints struct { + AddSprintEndpoint endpoint.Endpoint + + CloseSprintEndpoint endpoint.Endpoint + + GetSprintEndpoint endpoint.Endpoint +} + +func (e *Endpoints) AddSprint(ctx context.Context, in *pb.AddSprintRequest) (*pb.AddSprintResponse, error) { + out, err := e.AddSprintEndpoint(ctx, in) + if err != nil { + return &pb.AddSprintResponse{ErrMsg: err.Error()}, err + } + return out.(*pb.AddSprintReply), err +} + +func (e *Endpoints) CloseSprint(ctx context.Context, in *pb.CloseSprintRequest) (*pb.CloseSprintResponse, error) { + out, err := e.CloseSprintEndpoint(ctx, in) + if err != nil { + return &pb.CloseSprintResponse{ErrMsg: err.Error()}, err + } + return out.(*pb.CloseSprintReply), err +} + +func (e *Endpoints) GetSprint(ctx context.Context, in *pb.GetSprintRequest) (*pb.GetSprintResponse, error) { + out, err := e.GetSprintEndpoint(ctx, in) + if err != nil { + return &pb.GetSprintResponse{ErrMsg: err.Error()}, err + } + return out.(*pb.GetSprintReply), err +} + +func MakeAddSprintEndpoint(svc pb.SprintServiceServer) endpoint.Endpoint { + return func(ctx context.Context, request interface{}) (interface{}, error) { + req := request.(*pb.AddSprintRequest) + rep, err := svc.AddSprint(ctx, req) + if err != nil { + return &pb.AddSprintReply{ErrMsg: err.Error()}, err + } + return rep, nil + } +} + +func MakeCloseSprintEndpoint(svc pb.SprintServiceServer) endpoint.Endpoint { + return func(ctx context.Context, request interface{}) (interface{}, error) { + req := request.(*pb.CloseSprintRequest) + rep, err := svc.CloseSprint(ctx, req) + if err != nil { + return &pb.CloseSprintReply{ErrMsg: err.Error()}, err + } + return rep, nil + } +} + +func MakeGetSprintEndpoint(svc pb.SprintServiceServer) endpoint.Endpoint { + return func(ctx context.Context, request interface{}) (interface{}, error) { + req := request.(*pb.GetSprintRequest) + rep, err := svc.GetSprint(ctx, req) + if err != nil { + return &pb.GetSprintReply{ErrMsg: err.Error()}, err + } + return rep, nil + } +} + +func MakeEndpoints(svc pb.SprintServiceServer) Endpoints { + return Endpoints{ + + AddSprintEndpoint: MakeAddSprintEndpoint(svc), + + CloseSprintEndpoint: MakeCloseSprintEndpoint(svc), + + GetSprintEndpoint: MakeGetSprintEndpoint(svc), + } +} diff --git a/examples/go-kit/services/sprint/gen/init/init.go b/examples/go-kit/services/sprint/gen/init/init.go deleted file mode 100644 index 4a970cc..0000000 --- a/examples/go-kit/services/sprint/gen/init/init.go +++ /dev/null @@ -1 +0,0 @@ -package sprint_init diff --git a/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go b/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go index aa115af..fe209c2 100644 --- a/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go +++ b/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go @@ -1 +1,102 @@ package sprint_transportgrpc + +import ( + "fmt" + + grpctransport "github.com/go-kit/kit/transport/grpc" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint" + endpoint "github.com/moul/protoc-gen-gotemplate/examples/go-kit/sprint/gen/endpoints" + context "golang.org/x/net/context" +) + +// avoid import errors +var _ = fmt.Errorf + +func MakeGRPCServer(ctx context.Context, endpoints endpoint.Endpoints) pb.SprintServiceServer { + options := []grpctransport.ServerOption{} + return &grpcServer{ + + addsprint: grpctransport.NewServer( + ctx, + endpoints.AddSprintEndpoint, + decodeAddSprintRequest, + encodeAddSprintResponse, + options, + ), + + closesprint: grpctransport.NewServer( + ctx, + endpoints.CloseSprintEndpoint, + decodeCloseSprintRequest, + encodeCloseSprintResponse, + options, + ), + + getsprint: grpctransport.NewServer( + ctx, + endpoints.GetSprintEndpoint, + decodeGetSprintRequest, + encodeGetSprintResponse, + options, + ), + } +} + +type grpcServer struct { + addsprint grpctransport.Handler + + closesprint grpctransport.Handler + + getsprint grpctransport.Handler +} + +func (s *grpcServer) AddSprint(ctx context.Context, req *pb.AddSprintRequest) (*pb.AddSprintReply, error) { + _, rep, err := s.addsprint.ServeGRPC(ctx, req) + if err != nil { + return nil, err + } + return rep.(*pb.AddSprintReply), nil +} + +func decodeAddSprintRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) { + return grpcReq, nil +} + +func encodeAddSprintResponse(ctx context.Context, response interface{}) (interface{}, error) { + resp := response.(*pb.AddSprintReply) + return resp, nil +} + +func (s *grpcServer) CloseSprint(ctx context.Context, req *pb.CloseSprintRequest) (*pb.CloseSprintReply, error) { + _, rep, err := s.closesprint.ServeGRPC(ctx, req) + if err != nil { + return nil, err + } + return rep.(*pb.CloseSprintReply), nil +} + +func decodeCloseSprintRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) { + return grpcReq, nil +} + +func encodeCloseSprintResponse(ctx context.Context, response interface{}) (interface{}, error) { + resp := response.(*pb.CloseSprintReply) + return resp, nil +} + +func (s *grpcServer) GetSprint(ctx context.Context, req *pb.GetSprintRequest) (*pb.GetSprintReply, error) { + _, rep, err := s.getsprint.ServeGRPC(ctx, req) + if err != nil { + return nil, err + } + return rep.(*pb.GetSprintReply), nil +} + +func decodeGetSprintRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) { + return grpcReq, nil +} + +func encodeGetSprintResponse(ctx context.Context, response interface{}) (interface{}, error) { + resp := response.(*pb.GetSprintReply) + return resp, nil +} diff --git a/examples/go-kit/services/sprint/gen/transports/http/http.go b/examples/go-kit/services/sprint/gen/transports/http/http.go index 540b97b..48a8a2b 100644 --- a/examples/go-kit/services/sprint/gen/transports/http/http.go +++ b/examples/go-kit/services/sprint/gen/transports/http/http.go @@ -1 +1,93 @@ package sprint_transporthttp + +import ( + "encoding/json" + context "golang.org/x/net/context" + "log" + "net/http" + + gokit_endpoint "github.com/go-kit/kit/endpoint" + httptransport "github.com/go-kit/kit/transport/http" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint" + endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/sprint/gen/endpoints" +) + +func MakeAddSprintHandler(ctx context.Context, svc pb.SprintServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server { + return httptransport.NewServer( + ctx, + endpoint, + decodeAddSprintRequest, + encodeAddSprintResponse, + append([]httptransport.ServerOption{}, httptransport.ServerBefore(jwt.ToHTTPContext()))..., + ) +} + +func decodeAddSprintRequest(ctx context.Context, r *http.Request) (interface{}, error) { + var req pb.AddSprintRequest + if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + return nil, err + } + return &req, nil +} + +func encodeAddSprintResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { + return json.NewEncoder(w).Encode(response) +} + +func MakeCloseSprintHandler(ctx context.Context, svc pb.SprintServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server { + return httptransport.NewServer( + ctx, + endpoint, + decodeCloseSprintRequest, + encodeCloseSprintResponse, + append([]httptransport.ServerOption{}, httptransport.ServerBefore(jwt.ToHTTPContext()))..., + ) +} + +func decodeCloseSprintRequest(ctx context.Context, r *http.Request) (interface{}, error) { + var req pb.CloseSprintRequest + if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + return nil, err + } + return &req, nil +} + +func encodeCloseSprintResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { + return json.NewEncoder(w).Encode(response) +} + +func MakeGetSprintHandler(ctx context.Context, svc pb.SprintServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server { + return httptransport.NewServer( + ctx, + endpoint, + decodeGetSprintRequest, + encodeGetSprintResponse, + append([]httptransport.ServerOption{}, httptransport.ServerBefore(jwt.ToHTTPContext()))..., + ) +} + +func decodeGetSprintRequest(ctx context.Context, r *http.Request) (interface{}, error) { + var req pb.GetSprintRequest + if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + return nil, err + } + return &req, nil +} + +func encodeGetSprintResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error { + return json.NewEncoder(w).Encode(response) +} + +func RegisterHandlers(ctx context.Context, svc pb.SprintServiceServer, mux *http.ServeMux, endpoints endpoints.Endpoints) error { + + log.Println("new HTTP endpoint: \"/AddSprint\" (service=Sprint)") + mux.Handle("/AddSprint", MakeAddSprintHandler(ctx, svc, endpoints.AddSprintEndpoint)) + + log.Println("new HTTP endpoint: \"/CloseSprint\" (service=Sprint)") + mux.Handle("/CloseSprint", MakeCloseSprintHandler(ctx, svc, endpoints.CloseSprintEndpoint)) + + log.Println("new HTTP endpoint: \"/GetSprint\" (service=Sprint)") + mux.Handle("/GetSprint", MakeGetSprintHandler(ctx, svc, endpoints.GetSprintEndpoint)) + + return nil +} diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/client/client.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/client/client.go.tmpl deleted file mode 100644 index 361fda1..0000000 --- a/examples/go-kit/templates/{{.File.Package}}/gen/client/client.go.tmpl +++ /dev/null @@ -1 +0,0 @@ -package {{.File.Package}}_client \ No newline at end of file diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/cmd/{{.File.Package}}/main.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/cmd/{{.File.Package}}/main.go.tmpl deleted file mode 100644 index 85f0393..0000000 --- a/examples/go-kit/templates/{{.File.Package}}/gen/cmd/{{.File.Package}}/main.go.tmpl +++ /dev/null @@ -1 +0,0 @@ -package main \ No newline at end of file diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/endpoints/endpoints.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/endpoints/endpoints.go.tmpl index 0189f91..654d705 100644 --- a/examples/go-kit/templates/{{.File.Package}}/gen/endpoints/endpoints.go.tmpl +++ b/examples/go-kit/templates/{{.File.Package}}/gen/endpoints/endpoints.go.tmpl @@ -1 +1,49 @@ -package {{.File.Package}}_endpoints \ No newline at end of file +package {{.File.Package}}_endpoints + +{{$file := .File}} + +import ( + "fmt" + context "golang.org/x/net/context" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}" + "github.com/go-kit/kit/endpoint" +) + +var _ = fmt.Errorf + +type Endpoints struct { + {{range .Service.Method}} + {{.Name}}Endpoint endpoint.Endpoint + {{end}} +} + +{{range .Service.Method}} +func (e *Endpoints){{.Name}}(ctx context.Context, in *pb.{{.Name}}Request) (*pb.{{.Name}}Response, error) { + out, err := e.{{.Name}}Endpoint(ctx, in) + if err != nil { + return &pb.{{.Name}}Response{ErrMsg: err.Error()}, err + } + return out.(*pb.{{.Name}}Reply), err +} +{{end}} + +{{range .Service.Method}} +func Make{{.Name}}Endpoint(svc pb.{{$file.Package | title}}ServiceServer) endpoint.Endpoint { + return func(ctx context.Context, request interface{}) (interface{}, error) { + req := request.(*pb.{{.Name}}Request) + rep, err := svc.{{.Name}}(ctx, req) + if err != nil { + return &pb.{{.Name}}Reply{ErrMsg: err.Error()}, err + } + return rep, nil + } +} +{{end}} + +func MakeEndpoints(svc pb.{{.File.Package | title}}ServiceServer) Endpoints { + return Endpoints{ + {{range .Service.Method}} + {{.Name}}Endpoint: Make{{.Name}}Endpoint(svc), + {{end}} + } +} diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/init/init.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/init/init.go.tmpl deleted file mode 100644 index 176248c..0000000 --- a/examples/go-kit/templates/{{.File.Package}}/gen/init/init.go.tmpl +++ /dev/null @@ -1 +0,0 @@ -package {{.File.Package}}_init \ No newline at end of file diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl index 9b86de9..22ab6b3 100644 --- a/examples/go-kit/templates/{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl +++ b/examples/go-kit/templates/{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl @@ -1 +1,59 @@ -package {{.File.Package}}_transportgrpc \ No newline at end of file +package {{.File.Package}}_transportgrpc + +{{$file := .File}} + +import ( + "fmt" + + context "golang.org/x/net/context" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}" + grpctransport "github.com/go-kit/kit/transport/grpc" + endpoint "github.com/moul/protoc-gen-gotemplate/examples/go-kit/{{.File.Package}}/gen/endpoints" +) + +// avoid import errors +var _ = fmt.Errorf + +func MakeGRPCServer(ctx context.Context, endpoints endpoint.Endpoints) pb.{{.File.Package | title}}ServiceServer { + options := []grpctransport.ServerOption{} + return &grpcServer{ + {{range .Service.Method}} + {{if not .ServerStreaming}} + {{if not .ClientStreaming}} + {{.Name | lower}}: grpctransport.NewServer( + ctx, + endpoints.{{.Name}}Endpoint, + decode{{.Name}}Request, + encode{{.Name}}Response, + options, + ), + {{end}} + {{end}} + {{end}} + } +} + +type grpcServer struct { + {{range .Service.Method}} + {{.Name | lower}} grpctransport.Handler + {{end}} +} + +{{range .Service.Method}} +func (s *grpcServer) {{.Name}}(ctx context.Context, req *pb.{{.Name}}Request) (*pb.{{.Name}}Reply, error) { + _, rep, err := s.{{.Name | lower}}.ServeGRPC(ctx, req) + if err != nil { + return nil, err + } + return rep.(*pb.{{.Name}}Reply), nil +} + +func decode{{.Name}}Request(ctx context.Context, grpcReq interface{}) (interface{}, error) { + return grpcReq, nil +} + +func encode{{.Name}}Response(ctx context.Context, response interface{}) (interface{}, error) { + resp := response.(*pb.{{.Name}}Reply) + return resp, nil +} +{{end}} diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/transports/http/http.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/transports/http/http.go.tmpl index ff0559d..ece0496 100644 --- a/examples/go-kit/templates/{{.File.Package}}/gen/transports/http/http.go.tmpl +++ b/examples/go-kit/templates/{{.File.Package}}/gen/transports/http/http.go.tmpl @@ -1 +1,47 @@ -package {{.File.Package}}_transporthttp \ No newline at end of file +package {{.File.Package}}_transporthttp + +{{$file := .File}} + +import ( + "log" + "net/http" + "encoding/json" + context "golang.org/x/net/context" + + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}" + gokit_endpoint "github.com/go-kit/kit/endpoint" + httptransport "github.com/go-kit/kit/transport/http" + endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/{{.File.Package}}/gen/endpoints" +) + +{{range .Service.Method}} +func Make{{.Name}}Handler(ctx context.Context, svc pb.{{$file.Package | title}}ServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server { + return httptransport.NewServer( + ctx, + endpoint, + decode{{.Name}}Request, + encode{{.Name}}Response, + append([]httptransport.ServerOption{}, httptransport.ServerBefore(jwt.ToHTTPContext()))..., + ) +} + +func decode{{.Name}}Request(ctx context.Context, r *http.Request) (interface{}, error) { + var req pb.{{.Name}}Request + if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + return nil, err + } + return &req, nil +} + +func encode{{.Name}}Response(ctx context.Context, w http.ResponseWriter, response interface{}) error { + return json.NewEncoder(w).Encode(response) +} +{{end}} + +func RegisterHandlers(ctx context.Context, svc pb.{{$file.Package | title}}ServiceServer, mux *http.ServeMux, endpoints endpoints.Endpoints) error { + {{range .Service.Method}} + log.Println("new HTTP endpoint: \"/{{.Name}}\" (service={{$file.Package | title}})") + mux.Handle("/{{.Name}}", Make{{.Name}}Handler(ctx, svc, endpoints.{{.Name}}Endpoint)) + {{end}} + return nil +} From d748878896c4ff7dfac155757130ead3f54ae050 Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Tue, 13 Dec 2016 16:03:16 +0100 Subject: [PATCH 6/7] Add entrypoint --- examples/go-kit/.gitignore | 1 + examples/go-kit/Makefile | 7 +- examples/go-kit/main.go | 73 +++++++ .../session/gen/endpoints/endpoints.go | 8 +- .../session/gen/transports/grpc/grpc.go | 20 +- .../session/gen/transports/http/http.go | 8 +- .../session/services/session/session.pb.go | 98 --------- .../go-kit/services/session/session.pb.go | 152 +++++++++++++ .../go-kit/services/session/svc/service.go | 23 ++ .../sprint/gen/endpoints/endpoints.go | 12 +- .../sprint/gen/transports/grpc/grpc.go | 28 +-- .../sprint/gen/transports/http/http.go | 10 +- .../sprint/services/sprint/sprint.pb.go | 151 ------------- examples/go-kit/services/sprint/sprint.pb.go | 206 ++++++++++++++++++ .../go-kit/services/sprint/svc/service.go | 27 +++ .../gen/endpoints/endpoints.go.tmpl | 4 +- .../gen/transports/grpc/grpc.go.tmpl | 12 +- .../gen/transports/http/http.go.tmpl | 6 +- 18 files changed, 541 insertions(+), 305 deletions(-) create mode 100644 examples/go-kit/.gitignore create mode 100644 examples/go-kit/main.go delete mode 100644 examples/go-kit/services/session/services/session/session.pb.go create mode 100644 examples/go-kit/services/session/svc/service.go delete mode 100644 examples/go-kit/services/sprint/services/sprint/sprint.pb.go create mode 100644 examples/go-kit/services/sprint/svc/service.go diff --git a/examples/go-kit/.gitignore b/examples/go-kit/.gitignore new file mode 100644 index 0000000..06845b1 --- /dev/null +++ b/examples/go-kit/.gitignore @@ -0,0 +1 @@ +/server diff --git a/examples/go-kit/Makefile b/examples/go-kit/Makefile index 69c6cec..ec0c065 100644 --- a/examples/go-kit/Makefile +++ b/examples/go-kit/Makefile @@ -4,10 +4,13 @@ TARGETS_GO := $(foreach source, $(SOURCES), $(source)_go) TARGETS_TMPL := $(foreach source, $(SOURCES), $(source)_tmpl) .PHONY: build -build: $(TARGETS_GO) $(TARGETS_TMPL) +build: server + +server: $(TARGETS_GO) $(TARGETS_TMPL) + go build -o server . $(TARGETS_GO): %_go: - protoc --gogo_out=. "$*" + protoc --gogo_out=plugins=grpc:. "$*" $(TARGETS_TMPL): %_tmpl: @mkdir -p $(dir $*)gen diff --git a/examples/go-kit/main.go b/examples/go-kit/main.go new file mode 100644 index 0000000..719e10a --- /dev/null +++ b/examples/go-kit/main.go @@ -0,0 +1,73 @@ +package main + +import ( + "context" + "fmt" + "net" + "net/http" + "os" + "os/signal" + "syscall" + + "github.com/go-kit/kit/log" + "github.com/gorilla/handlers" + "google.golang.org/grpc" + + session_pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session" + session_endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints" + session_grpctransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/transports/grpc" + session_httptransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/transports/http" + sessionsvc "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/svc" +) + +func main() { + mux := http.NewServeMux() + ctx := context.Background() + errc := make(chan error) + s := grpc.NewServer() + var logger log.Logger + { + logger = log.NewLogfmtLogger(os.Stdout) + logger = log.NewContext(logger).With("ts", log.DefaultTimestampUTC) + logger = log.NewContext(logger).With("caller", log.DefaultCaller) + } + + // initialize services + { + svc := sessionsvc.New() + endpoints := session_endpoints.MakeEndpoints(svc) + srv := session_grpctransport.MakeGRPCServer(ctx, endpoints) + session_pb.RegisterSessionServiceServer(s, srv) + session_httptransport.RegisterHandlers(ctx, svc, mux, endpoints) + } + { + //svc := sprintsvc.New() + + } + + // start servers + go func() { + c := make(chan os.Signal, 1) + signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) + errc <- fmt.Errorf("%s", <-c) + }() + + go func() { + logger := log.NewContext(logger).With("transport", "HTTP") + logger.Log("addr", ":8000") + errc <- http.ListenAndServe(":8000", handlers.LoggingHandler(os.Stderr, mux)) + }() + + go func() { + logger := log.NewContext(logger).With("transport", "gRPC") + ln, err := net.Listen("tcp", ":9000") + if err != nil { + errc <- err + return + } + logger.Log("addr", ":9000") + errc <- s.Serve(ln) + }() + + logger.Log("exit", <-errc) +} diff --git a/examples/go-kit/services/session/gen/endpoints/endpoints.go b/examples/go-kit/services/session/gen/endpoints/endpoints.go index f64d456..eb1ee91 100644 --- a/examples/go-kit/services/session/gen/endpoints/endpoints.go +++ b/examples/go-kit/services/session/gen/endpoints/endpoints.go @@ -20,7 +20,7 @@ func (e *Endpoints) Login(ctx context.Context, in *pb.LoginRequest) (*pb.LoginRe if err != nil { return &pb.LoginResponse{ErrMsg: err.Error()}, err } - return out.(*pb.LoginReply), err + return out.(*pb.LoginResponse), err } func (e *Endpoints) Logout(ctx context.Context, in *pb.LogoutRequest) (*pb.LogoutResponse, error) { @@ -28,7 +28,7 @@ func (e *Endpoints) Logout(ctx context.Context, in *pb.LogoutRequest) (*pb.Logou if err != nil { return &pb.LogoutResponse{ErrMsg: err.Error()}, err } - return out.(*pb.LogoutReply), err + return out.(*pb.LogoutResponse), err } func MakeLoginEndpoint(svc pb.SessionServiceServer) endpoint.Endpoint { @@ -36,7 +36,7 @@ func MakeLoginEndpoint(svc pb.SessionServiceServer) endpoint.Endpoint { req := request.(*pb.LoginRequest) rep, err := svc.Login(ctx, req) if err != nil { - return &pb.LoginReply{ErrMsg: err.Error()}, err + return &pb.LoginResponse{ErrMsg: err.Error()}, err } return rep, nil } @@ -47,7 +47,7 @@ func MakeLogoutEndpoint(svc pb.SessionServiceServer) endpoint.Endpoint { req := request.(*pb.LogoutRequest) rep, err := svc.Logout(ctx, req) if err != nil { - return &pb.LogoutReply{ErrMsg: err.Error()}, err + return &pb.LogoutResponse{ErrMsg: err.Error()}, err } return rep, nil } diff --git a/examples/go-kit/services/session/gen/transports/grpc/grpc.go b/examples/go-kit/services/session/gen/transports/grpc/grpc.go index 4fce3bb..45fd4e0 100644 --- a/examples/go-kit/services/session/gen/transports/grpc/grpc.go +++ b/examples/go-kit/services/session/gen/transports/grpc/grpc.go @@ -1,11 +1,11 @@ -package session_transportgrpc +package session_grpctransport import ( "fmt" grpctransport "github.com/go-kit/kit/transport/grpc" pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session" - endpoint "github.com/moul/protoc-gen-gotemplate/examples/go-kit/session/gen/endpoints" + endpoint "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints" context "golang.org/x/net/context" ) @@ -21,7 +21,7 @@ func MakeGRPCServer(ctx context.Context, endpoints endpoint.Endpoints) pb.Sessio endpoints.LoginEndpoint, decodeLoginRequest, encodeLoginResponse, - options, + options..., ), logout: grpctransport.NewServer( @@ -29,7 +29,7 @@ func MakeGRPCServer(ctx context.Context, endpoints endpoint.Endpoints) pb.Sessio endpoints.LogoutEndpoint, decodeLogoutRequest, encodeLogoutResponse, - options, + options..., ), } } @@ -40,12 +40,12 @@ type grpcServer struct { logout grpctransport.Handler } -func (s *grpcServer) Login(ctx context.Context, req *pb.LoginRequest) (*pb.LoginReply, error) { +func (s *grpcServer) Login(ctx context.Context, req *pb.LoginRequest) (*pb.LoginResponse, error) { _, rep, err := s.login.ServeGRPC(ctx, req) if err != nil { return nil, err } - return rep.(*pb.LoginReply), nil + return rep.(*pb.LoginResponse), nil } func decodeLoginRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) { @@ -53,16 +53,16 @@ func decodeLoginRequest(ctx context.Context, grpcReq interface{}) (interface{}, } func encodeLoginResponse(ctx context.Context, response interface{}) (interface{}, error) { - resp := response.(*pb.LoginReply) + resp := response.(*pb.LoginResponse) return resp, nil } -func (s *grpcServer) Logout(ctx context.Context, req *pb.LogoutRequest) (*pb.LogoutReply, error) { +func (s *grpcServer) Logout(ctx context.Context, req *pb.LogoutRequest) (*pb.LogoutResponse, error) { _, rep, err := s.logout.ServeGRPC(ctx, req) if err != nil { return nil, err } - return rep.(*pb.LogoutReply), nil + return rep.(*pb.LogoutResponse), nil } func decodeLogoutRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) { @@ -70,6 +70,6 @@ func decodeLogoutRequest(ctx context.Context, grpcReq interface{}) (interface{}, } func encodeLogoutResponse(ctx context.Context, response interface{}) (interface{}, error) { - resp := response.(*pb.LogoutReply) + resp := response.(*pb.LogoutResponse) return resp, nil } diff --git a/examples/go-kit/services/session/gen/transports/http/http.go b/examples/go-kit/services/session/gen/transports/http/http.go index 842e4d0..0bdbfeb 100644 --- a/examples/go-kit/services/session/gen/transports/http/http.go +++ b/examples/go-kit/services/session/gen/transports/http/http.go @@ -1,4 +1,4 @@ -package session_transporthttp +package session_httptransport import ( "encoding/json" @@ -9,7 +9,7 @@ import ( gokit_endpoint "github.com/go-kit/kit/endpoint" httptransport "github.com/go-kit/kit/transport/http" pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session" - endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/session/gen/endpoints" + endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints" ) func MakeLoginHandler(ctx context.Context, svc pb.SessionServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server { @@ -18,7 +18,7 @@ func MakeLoginHandler(ctx context.Context, svc pb.SessionServiceServer, endpoint endpoint, decodeLoginRequest, encodeLoginResponse, - append([]httptransport.ServerOption{}, httptransport.ServerBefore(jwt.ToHTTPContext()))..., + []httptransport.ServerOption{}..., ) } @@ -40,7 +40,7 @@ func MakeLogoutHandler(ctx context.Context, svc pb.SessionServiceServer, endpoin endpoint, decodeLogoutRequest, encodeLogoutResponse, - append([]httptransport.ServerOption{}, httptransport.ServerBefore(jwt.ToHTTPContext()))..., + []httptransport.ServerOption{}..., ) } diff --git a/examples/go-kit/services/session/services/session/session.pb.go b/examples/go-kit/services/session/services/session/session.pb.go deleted file mode 100644 index c07e0a0..0000000 --- a/examples/go-kit/services/session/services/session/session.pb.go +++ /dev/null @@ -1,98 +0,0 @@ -// Code generated by protoc-gen-gogo. -// source: services/session/session.proto -// DO NOT EDIT! - -/* -Package session is a generated protocol buffer package. - -It is generated from these files: - services/session/session.proto - -It has these top-level messages: - LoginRequest - LoginResponse - LogoutRequest - LogoutResponse -*/ -package session - -import proto "github.com/gogo/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 - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package - -type LoginRequest struct { - Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` - Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` -} - -func (m *LoginRequest) Reset() { *m = LoginRequest{} } -func (m *LoginRequest) String() string { return proto.CompactTextString(m) } -func (*LoginRequest) ProtoMessage() {} -func (*LoginRequest) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{0} } - -type LoginResponse struct { - Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` - ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` -} - -func (m *LoginResponse) Reset() { *m = LoginResponse{} } -func (m *LoginResponse) String() string { return proto.CompactTextString(m) } -func (*LoginResponse) ProtoMessage() {} -func (*LoginResponse) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{1} } - -type LogoutRequest struct { - Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` -} - -func (m *LogoutRequest) Reset() { *m = LogoutRequest{} } -func (m *LogoutRequest) String() string { return proto.CompactTextString(m) } -func (*LogoutRequest) ProtoMessage() {} -func (*LogoutRequest) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{2} } - -type LogoutResponse struct { - ErrMsg string `protobuf:"bytes,1,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` -} - -func (m *LogoutResponse) Reset() { *m = LogoutResponse{} } -func (m *LogoutResponse) String() string { return proto.CompactTextString(m) } -func (*LogoutResponse) ProtoMessage() {} -func (*LogoutResponse) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{3} } - -func init() { - proto.RegisterType((*LoginRequest)(nil), "session.LoginRequest") - proto.RegisterType((*LoginResponse)(nil), "session.LoginResponse") - proto.RegisterType((*LogoutRequest)(nil), "session.LogoutRequest") - proto.RegisterType((*LogoutResponse)(nil), "session.LogoutResponse") -} - -func init() { proto.RegisterFile("services/session/session.proto", fileDescriptorSession) } - -var fileDescriptorSession = []byte{ - // 231 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x6c, 0x50, 0xcb, 0x4a, 0xc5, 0x30, - 0x10, 0x35, 0xc2, 0xed, 0xd5, 0x41, 0xef, 0x62, 0x50, 0x6f, 0xe9, 0x42, 0x24, 0x20, 0xe8, 0xa6, - 0x82, 0x6e, 0x04, 0xc1, 0xa5, 0x2b, 0xdd, 0xb4, 0x1f, 0x20, 0x55, 0x87, 0x52, 0xa4, 0x99, 0x3a, - 0x93, 0xea, 0x27, 0xf8, 0xdb, 0x62, 0x93, 0x68, 0x7d, 0xac, 0xc2, 0xc9, 0xcc, 0x79, 0xcc, 0x81, - 0x43, 0x25, 0x79, 0xed, 0x1e, 0x49, 0xcf, 0x94, 0x54, 0x3b, 0x76, 0xe9, 0x2d, 0x07, 0x61, 0xcf, - 0xb8, 0x8c, 0xd0, 0xde, 0xc0, 0xce, 0x2d, 0xb7, 0x9d, 0xab, 0xe8, 0x65, 0x24, 0xf5, 0x58, 0xc0, - 0xd6, 0xa8, 0x24, 0xae, 0xe9, 0x29, 0x37, 0x47, 0xe6, 0x64, 0xbb, 0xfa, 0xc2, 0x9f, 0xb3, 0xa1, - 0x51, 0x7d, 0x63, 0x79, 0xca, 0x37, 0xc3, 0x2c, 0x61, 0x7b, 0x0d, 0xbb, 0x51, 0x47, 0x07, 0x76, - 0x4a, 0xb8, 0x07, 0x0b, 0xcf, 0xcf, 0xe4, 0xa2, 0x4a, 0x00, 0xb8, 0x86, 0x25, 0x89, 0xdc, 0xf7, - 0xda, 0x46, 0x85, 0x8c, 0x44, 0xee, 0xb4, 0xb5, 0xc7, 0x13, 0x9f, 0x47, 0x9f, 0x82, 0xfc, 0xcb, - 0xb7, 0xa7, 0xb0, 0x4a, 0x6b, 0xd1, 0x67, 0xa6, 0x68, 0xe6, 0x8a, 0xe7, 0xef, 0x06, 0x56, 0x75, - 0xb8, 0xb2, 0x0e, 0x65, 0xe0, 0x25, 0x2c, 0xa6, 0x90, 0xb8, 0x5f, 0xa6, 0x3a, 0xe6, 0xc7, 0x17, - 0x07, 0xbf, 0xbf, 0x83, 0x87, 0xdd, 0xc0, 0x2b, 0xc8, 0x82, 0x2f, 0xfe, 0xd8, 0xf9, 0xce, 0x5b, - 0xac, 0xff, 0xfc, 0x27, 0xf2, 0x43, 0x36, 0x75, 0x7e, 0xf1, 0x11, 0x00, 0x00, 0xff, 0xff, 0xc7, - 0x91, 0x50, 0x79, 0x95, 0x01, 0x00, 0x00, -} diff --git a/examples/go-kit/services/session/session.pb.go b/examples/go-kit/services/session/session.pb.go index c07e0a0..375f7f5 100644 --- a/examples/go-kit/services/session/session.pb.go +++ b/examples/go-kit/services/session/session.pb.go @@ -20,6 +20,11 @@ import proto "github.com/gogo/protobuf/proto" import fmt "fmt" import math "math" +import ( + context "golang.org/x/net/context" + grpc "google.golang.org/grpc" +) + // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf @@ -41,6 +46,20 @@ func (m *LoginRequest) String() string { return proto.CompactTextStri func (*LoginRequest) ProtoMessage() {} func (*LoginRequest) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{0} } +func (m *LoginRequest) GetUsername() string { + if m != nil { + return m.Username + } + return "" +} + +func (m *LoginRequest) GetPassword() string { + if m != nil { + return m.Password + } + return "" +} + type LoginResponse struct { Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` @@ -51,6 +70,20 @@ func (m *LoginResponse) String() string { return proto.CompactTextStr func (*LoginResponse) ProtoMessage() {} func (*LoginResponse) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{1} } +func (m *LoginResponse) GetToken() string { + if m != nil { + return m.Token + } + return "" +} + +func (m *LoginResponse) GetErrMsg() string { + if m != nil { + return m.ErrMsg + } + return "" +} + type LogoutRequest struct { Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` } @@ -60,6 +93,13 @@ func (m *LogoutRequest) String() string { return proto.CompactTextStr func (*LogoutRequest) ProtoMessage() {} func (*LogoutRequest) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{2} } +func (m *LogoutRequest) GetToken() string { + if m != nil { + return m.Token + } + return "" +} + type LogoutResponse struct { ErrMsg string `protobuf:"bytes,1,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` } @@ -69,6 +109,13 @@ func (m *LogoutResponse) String() string { return proto.CompactTextSt func (*LogoutResponse) ProtoMessage() {} func (*LogoutResponse) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{3} } +func (m *LogoutResponse) GetErrMsg() string { + if m != nil { + return m.ErrMsg + } + return "" +} + func init() { proto.RegisterType((*LoginRequest)(nil), "session.LoginRequest") proto.RegisterType((*LoginResponse)(nil), "session.LoginResponse") @@ -76,6 +123,111 @@ func init() { proto.RegisterType((*LogoutResponse)(nil), "session.LogoutResponse") } +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// Client API for SessionService service + +type SessionServiceClient interface { + Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) + Logout(ctx context.Context, in *LogoutRequest, opts ...grpc.CallOption) (*LogoutResponse, error) +} + +type sessionServiceClient struct { + cc *grpc.ClientConn +} + +func NewSessionServiceClient(cc *grpc.ClientConn) SessionServiceClient { + return &sessionServiceClient{cc} +} + +func (c *sessionServiceClient) Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) { + out := new(LoginResponse) + err := grpc.Invoke(ctx, "/session.SessionService/Login", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *sessionServiceClient) Logout(ctx context.Context, in *LogoutRequest, opts ...grpc.CallOption) (*LogoutResponse, error) { + out := new(LogoutResponse) + err := grpc.Invoke(ctx, "/session.SessionService/Logout", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for SessionService service + +type SessionServiceServer interface { + Login(context.Context, *LoginRequest) (*LoginResponse, error) + Logout(context.Context, *LogoutRequest) (*LogoutResponse, error) +} + +func RegisterSessionServiceServer(s *grpc.Server, srv SessionServiceServer) { + s.RegisterService(&_SessionService_serviceDesc, srv) +} + +func _SessionService_Login_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LoginRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SessionServiceServer).Login(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/session.SessionService/Login", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SessionServiceServer).Login(ctx, req.(*LoginRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _SessionService_Logout_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LogoutRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SessionServiceServer).Logout(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/session.SessionService/Logout", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SessionServiceServer).Logout(ctx, req.(*LogoutRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _SessionService_serviceDesc = grpc.ServiceDesc{ + ServiceName: "session.SessionService", + HandlerType: (*SessionServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Login", + Handler: _SessionService_Login_Handler, + }, + { + MethodName: "Logout", + Handler: _SessionService_Logout_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "services/session/session.proto", +} + func init() { proto.RegisterFile("services/session/session.proto", fileDescriptorSession) } var fileDescriptorSession = []byte{ diff --git a/examples/go-kit/services/session/svc/service.go b/examples/go-kit/services/session/svc/service.go new file mode 100644 index 0000000..bbb9070 --- /dev/null +++ b/examples/go-kit/services/session/svc/service.go @@ -0,0 +1,23 @@ +package sessionsvc + +import ( + "fmt" + + "golang.org/x/net/context" + + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session" +) + +type Service struct{} + +func New() pb.SessionServiceServer { + return &Service{} +} + +func (svc *Service) Login(ctx context.Context, in *pb.LoginRequest) (*pb.LoginResponse, error) { + return nil, fmt.Errorf("not implemented") +} + +func (svc *Service) Logout(ctx context.Context, in *pb.LogoutRequest) (*pb.LogoutResponse, error) { + return nil, fmt.Errorf("not implemented") +} diff --git a/examples/go-kit/services/sprint/gen/endpoints/endpoints.go b/examples/go-kit/services/sprint/gen/endpoints/endpoints.go index a58ff09..bcad549 100644 --- a/examples/go-kit/services/sprint/gen/endpoints/endpoints.go +++ b/examples/go-kit/services/sprint/gen/endpoints/endpoints.go @@ -22,7 +22,7 @@ func (e *Endpoints) AddSprint(ctx context.Context, in *pb.AddSprintRequest) (*pb if err != nil { return &pb.AddSprintResponse{ErrMsg: err.Error()}, err } - return out.(*pb.AddSprintReply), err + return out.(*pb.AddSprintResponse), err } func (e *Endpoints) CloseSprint(ctx context.Context, in *pb.CloseSprintRequest) (*pb.CloseSprintResponse, error) { @@ -30,7 +30,7 @@ func (e *Endpoints) CloseSprint(ctx context.Context, in *pb.CloseSprintRequest) if err != nil { return &pb.CloseSprintResponse{ErrMsg: err.Error()}, err } - return out.(*pb.CloseSprintReply), err + return out.(*pb.CloseSprintResponse), err } func (e *Endpoints) GetSprint(ctx context.Context, in *pb.GetSprintRequest) (*pb.GetSprintResponse, error) { @@ -38,7 +38,7 @@ func (e *Endpoints) GetSprint(ctx context.Context, in *pb.GetSprintRequest) (*pb if err != nil { return &pb.GetSprintResponse{ErrMsg: err.Error()}, err } - return out.(*pb.GetSprintReply), err + return out.(*pb.GetSprintResponse), err } func MakeAddSprintEndpoint(svc pb.SprintServiceServer) endpoint.Endpoint { @@ -46,7 +46,7 @@ func MakeAddSprintEndpoint(svc pb.SprintServiceServer) endpoint.Endpoint { req := request.(*pb.AddSprintRequest) rep, err := svc.AddSprint(ctx, req) if err != nil { - return &pb.AddSprintReply{ErrMsg: err.Error()}, err + return &pb.AddSprintResponse{ErrMsg: err.Error()}, err } return rep, nil } @@ -57,7 +57,7 @@ func MakeCloseSprintEndpoint(svc pb.SprintServiceServer) endpoint.Endpoint { req := request.(*pb.CloseSprintRequest) rep, err := svc.CloseSprint(ctx, req) if err != nil { - return &pb.CloseSprintReply{ErrMsg: err.Error()}, err + return &pb.CloseSprintResponse{ErrMsg: err.Error()}, err } return rep, nil } @@ -68,7 +68,7 @@ func MakeGetSprintEndpoint(svc pb.SprintServiceServer) endpoint.Endpoint { req := request.(*pb.GetSprintRequest) rep, err := svc.GetSprint(ctx, req) if err != nil { - return &pb.GetSprintReply{ErrMsg: err.Error()}, err + return &pb.GetSprintResponse{ErrMsg: err.Error()}, err } return rep, nil } diff --git a/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go b/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go index fe209c2..ca83972 100644 --- a/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go +++ b/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go @@ -1,11 +1,11 @@ -package sprint_transportgrpc +package sprint_grpctransport import ( "fmt" grpctransport "github.com/go-kit/kit/transport/grpc" pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint" - endpoint "github.com/moul/protoc-gen-gotemplate/examples/go-kit/sprint/gen/endpoints" + endpoint "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints" context "golang.org/x/net/context" ) @@ -21,7 +21,7 @@ func MakeGRPCServer(ctx context.Context, endpoints endpoint.Endpoints) pb.Sprint endpoints.AddSprintEndpoint, decodeAddSprintRequest, encodeAddSprintResponse, - options, + options..., ), closesprint: grpctransport.NewServer( @@ -29,7 +29,7 @@ func MakeGRPCServer(ctx context.Context, endpoints endpoint.Endpoints) pb.Sprint endpoints.CloseSprintEndpoint, decodeCloseSprintRequest, encodeCloseSprintResponse, - options, + options..., ), getsprint: grpctransport.NewServer( @@ -37,7 +37,7 @@ func MakeGRPCServer(ctx context.Context, endpoints endpoint.Endpoints) pb.Sprint endpoints.GetSprintEndpoint, decodeGetSprintRequest, encodeGetSprintResponse, - options, + options..., ), } } @@ -50,12 +50,12 @@ type grpcServer struct { getsprint grpctransport.Handler } -func (s *grpcServer) AddSprint(ctx context.Context, req *pb.AddSprintRequest) (*pb.AddSprintReply, error) { +func (s *grpcServer) AddSprint(ctx context.Context, req *pb.AddSprintRequest) (*pb.AddSprintResponse, error) { _, rep, err := s.addsprint.ServeGRPC(ctx, req) if err != nil { return nil, err } - return rep.(*pb.AddSprintReply), nil + return rep.(*pb.AddSprintResponse), nil } func decodeAddSprintRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) { @@ -63,16 +63,16 @@ func decodeAddSprintRequest(ctx context.Context, grpcReq interface{}) (interface } func encodeAddSprintResponse(ctx context.Context, response interface{}) (interface{}, error) { - resp := response.(*pb.AddSprintReply) + resp := response.(*pb.AddSprintResponse) return resp, nil } -func (s *grpcServer) CloseSprint(ctx context.Context, req *pb.CloseSprintRequest) (*pb.CloseSprintReply, error) { +func (s *grpcServer) CloseSprint(ctx context.Context, req *pb.CloseSprintRequest) (*pb.CloseSprintResponse, error) { _, rep, err := s.closesprint.ServeGRPC(ctx, req) if err != nil { return nil, err } - return rep.(*pb.CloseSprintReply), nil + return rep.(*pb.CloseSprintResponse), nil } func decodeCloseSprintRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) { @@ -80,16 +80,16 @@ func decodeCloseSprintRequest(ctx context.Context, grpcReq interface{}) (interfa } func encodeCloseSprintResponse(ctx context.Context, response interface{}) (interface{}, error) { - resp := response.(*pb.CloseSprintReply) + resp := response.(*pb.CloseSprintResponse) return resp, nil } -func (s *grpcServer) GetSprint(ctx context.Context, req *pb.GetSprintRequest) (*pb.GetSprintReply, error) { +func (s *grpcServer) GetSprint(ctx context.Context, req *pb.GetSprintRequest) (*pb.GetSprintResponse, error) { _, rep, err := s.getsprint.ServeGRPC(ctx, req) if err != nil { return nil, err } - return rep.(*pb.GetSprintReply), nil + return rep.(*pb.GetSprintResponse), nil } func decodeGetSprintRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) { @@ -97,6 +97,6 @@ func decodeGetSprintRequest(ctx context.Context, grpcReq interface{}) (interface } func encodeGetSprintResponse(ctx context.Context, response interface{}) (interface{}, error) { - resp := response.(*pb.GetSprintReply) + resp := response.(*pb.GetSprintResponse) return resp, nil } diff --git a/examples/go-kit/services/sprint/gen/transports/http/http.go b/examples/go-kit/services/sprint/gen/transports/http/http.go index 48a8a2b..492ead0 100644 --- a/examples/go-kit/services/sprint/gen/transports/http/http.go +++ b/examples/go-kit/services/sprint/gen/transports/http/http.go @@ -1,4 +1,4 @@ -package sprint_transporthttp +package sprint_httptransport import ( "encoding/json" @@ -9,7 +9,7 @@ import ( gokit_endpoint "github.com/go-kit/kit/endpoint" httptransport "github.com/go-kit/kit/transport/http" pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint" - endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/sprint/gen/endpoints" + endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints" ) func MakeAddSprintHandler(ctx context.Context, svc pb.SprintServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server { @@ -18,7 +18,7 @@ func MakeAddSprintHandler(ctx context.Context, svc pb.SprintServiceServer, endpo endpoint, decodeAddSprintRequest, encodeAddSprintResponse, - append([]httptransport.ServerOption{}, httptransport.ServerBefore(jwt.ToHTTPContext()))..., + []httptransport.ServerOption{}..., ) } @@ -40,7 +40,7 @@ func MakeCloseSprintHandler(ctx context.Context, svc pb.SprintServiceServer, end endpoint, decodeCloseSprintRequest, encodeCloseSprintResponse, - append([]httptransport.ServerOption{}, httptransport.ServerBefore(jwt.ToHTTPContext()))..., + []httptransport.ServerOption{}..., ) } @@ -62,7 +62,7 @@ func MakeGetSprintHandler(ctx context.Context, svc pb.SprintServiceServer, endpo endpoint, decodeGetSprintRequest, encodeGetSprintResponse, - append([]httptransport.ServerOption{}, httptransport.ServerBefore(jwt.ToHTTPContext()))..., + []httptransport.ServerOption{}..., ) } diff --git a/examples/go-kit/services/sprint/services/sprint/sprint.pb.go b/examples/go-kit/services/sprint/services/sprint/sprint.pb.go deleted file mode 100644 index 3246810..0000000 --- a/examples/go-kit/services/sprint/services/sprint/sprint.pb.go +++ /dev/null @@ -1,151 +0,0 @@ -// Code generated by protoc-gen-gogo. -// source: services/sprint/sprint.proto -// DO NOT EDIT! - -/* -Package sprint is a generated protocol buffer package. - -It is generated from these files: - services/sprint/sprint.proto - -It has these top-level messages: - AddSprintRequest - AddSprintResponse - CloseSprintRequest - CloseSprintResponse - GetSprintRequest - GetSprintResponse - Sprint -*/ -package sprint - -import proto "github.com/gogo/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 - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package - -type AddSprintRequest struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` -} - -func (m *AddSprintRequest) Reset() { *m = AddSprintRequest{} } -func (m *AddSprintRequest) String() string { return proto.CompactTextString(m) } -func (*AddSprintRequest) ProtoMessage() {} -func (*AddSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{0} } - -type AddSprintResponse struct { - Sprint *Sprint `protobuf:"bytes,1,opt,name=sprint" json:"sprint,omitempty"` - ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` -} - -func (m *AddSprintResponse) Reset() { *m = AddSprintResponse{} } -func (m *AddSprintResponse) String() string { return proto.CompactTextString(m) } -func (*AddSprintResponse) ProtoMessage() {} -func (*AddSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{1} } - -func (m *AddSprintResponse) GetSprint() *Sprint { - if m != nil { - return m.Sprint - } - return nil -} - -type CloseSprintRequest struct { - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` -} - -func (m *CloseSprintRequest) Reset() { *m = CloseSprintRequest{} } -func (m *CloseSprintRequest) String() string { return proto.CompactTextString(m) } -func (*CloseSprintRequest) ProtoMessage() {} -func (*CloseSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{2} } - -type CloseSprintResponse struct { - ErrMsg string `protobuf:"bytes,1,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` -} - -func (m *CloseSprintResponse) Reset() { *m = CloseSprintResponse{} } -func (m *CloseSprintResponse) String() string { return proto.CompactTextString(m) } -func (*CloseSprintResponse) ProtoMessage() {} -func (*CloseSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{3} } - -type GetSprintRequest struct { - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` -} - -func (m *GetSprintRequest) Reset() { *m = GetSprintRequest{} } -func (m *GetSprintRequest) String() string { return proto.CompactTextString(m) } -func (*GetSprintRequest) ProtoMessage() {} -func (*GetSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{4} } - -type GetSprintResponse struct { - Sprint *Sprint `protobuf:"bytes,1,opt,name=sprint" json:"sprint,omitempty"` - ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` -} - -func (m *GetSprintResponse) Reset() { *m = GetSprintResponse{} } -func (m *GetSprintResponse) String() string { return proto.CompactTextString(m) } -func (*GetSprintResponse) ProtoMessage() {} -func (*GetSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{5} } - -func (m *GetSprintResponse) GetSprint() *Sprint { - if m != nil { - return m.Sprint - } - return nil -} - -type Sprint struct { - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - CreatedAt uint32 `protobuf:"varint,2,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` - Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` -} - -func (m *Sprint) Reset() { *m = Sprint{} } -func (m *Sprint) String() string { return proto.CompactTextString(m) } -func (*Sprint) ProtoMessage() {} -func (*Sprint) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{6} } - -func init() { - proto.RegisterType((*AddSprintRequest)(nil), "sprint.AddSprintRequest") - proto.RegisterType((*AddSprintResponse)(nil), "sprint.AddSprintResponse") - proto.RegisterType((*CloseSprintRequest)(nil), "sprint.CloseSprintRequest") - proto.RegisterType((*CloseSprintResponse)(nil), "sprint.CloseSprintResponse") - proto.RegisterType((*GetSprintRequest)(nil), "sprint.GetSprintRequest") - proto.RegisterType((*GetSprintResponse)(nil), "sprint.GetSprintResponse") - proto.RegisterType((*Sprint)(nil), "sprint.Sprint") -} - -func init() { proto.RegisterFile("services/sprint/sprint.proto", fileDescriptorSprint) } - -var fileDescriptorSprint = []byte{ - // 290 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xac, 0x52, 0x4d, 0x4b, 0xc3, 0x40, - 0x10, 0x6d, 0xaa, 0x44, 0x32, 0xa5, 0xa5, 0x1d, 0x0f, 0xc6, 0xa8, 0x20, 0x8b, 0x14, 0x4f, 0x11, - 0xea, 0x2f, 0x68, 0x3d, 0x28, 0x88, 0x97, 0xb4, 0xf7, 0x12, 0xbb, 0x43, 0x09, 0xd8, 0x24, 0xee, - 0xac, 0xfe, 0x5f, 0xff, 0x89, 0xb0, 0xbb, 0xcd, 0x57, 0x8b, 0x27, 0x4f, 0xc9, 0xec, 0xbc, 0x7d, - 0x6f, 0xe6, 0xbd, 0x85, 0x6b, 0x26, 0xf5, 0x9d, 0x6d, 0x88, 0x1f, 0xb8, 0x54, 0x59, 0xae, 0xdd, - 0x27, 0x2e, 0x55, 0xa1, 0x0b, 0xf4, 0x6d, 0x25, 0xa6, 0x30, 0x9e, 0x4b, 0xb9, 0x34, 0x45, 0x42, - 0x9f, 0x5f, 0xc4, 0x1a, 0x11, 0x4e, 0xf3, 0x74, 0x47, 0xa1, 0x77, 0xeb, 0xdd, 0x07, 0x89, 0xf9, - 0x17, 0x2b, 0x98, 0x34, 0x70, 0x5c, 0x16, 0x39, 0x13, 0x4e, 0xc1, 0xd1, 0x18, 0xe8, 0x60, 0x36, - 0x8a, 0x9d, 0x86, 0xc3, 0xb9, 0x2e, 0x5e, 0xc0, 0x19, 0x29, 0xb5, 0xde, 0xf1, 0x36, 0xec, 0x1b, - 0x4e, 0x9f, 0x94, 0x7a, 0xe3, 0xad, 0xb8, 0x03, 0x7c, 0xfa, 0x28, 0x98, 0xda, 0xfa, 0x23, 0xe8, - 0x67, 0xd2, 0xa9, 0xf7, 0x33, 0x29, 0x62, 0x38, 0x6f, 0xa1, 0x9c, 0x7a, 0x83, 0xd5, 0x6b, 0xb1, - 0x0a, 0x18, 0x3f, 0x93, 0xfe, 0x9b, 0x73, 0x05, 0x93, 0x06, 0xe6, 0xbf, 0xf6, 0x79, 0x05, 0xdf, - 0x42, 0xbb, 0x7a, 0x78, 0x03, 0xb0, 0x51, 0x94, 0x6a, 0x92, 0xeb, 0x54, 0x9b, 0x5b, 0xc3, 0x24, - 0x70, 0x27, 0xf3, 0xda, 0xf2, 0x93, 0xda, 0xf2, 0xd9, 0x8f, 0x07, 0x43, 0xcb, 0xb6, 0xb4, 0x49, - 0xe2, 0x02, 0x82, 0x2a, 0x04, 0x0c, 0xf7, 0xc3, 0x75, 0xf3, 0x8b, 0x2e, 0x8f, 0x74, 0xec, 0x86, - 0xa2, 0x87, 0x2f, 0x30, 0x68, 0x98, 0x89, 0xd1, 0x1e, 0x7b, 0x98, 0x43, 0x74, 0x75, 0xb4, 0x57, - 0x31, 0x2d, 0x20, 0xa8, 0x2c, 0xac, 0xa7, 0xe9, 0x3a, 0x5f, 0x4f, 0x73, 0xe0, 0xb7, 0xe8, 0xbd, - 0xfb, 0xe6, 0x35, 0x3e, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x9e, 0xb2, 0x1e, 0xad, 0x02, - 0x00, 0x00, -} diff --git a/examples/go-kit/services/sprint/sprint.pb.go b/examples/go-kit/services/sprint/sprint.pb.go index 3246810..d06ebf4 100644 --- a/examples/go-kit/services/sprint/sprint.pb.go +++ b/examples/go-kit/services/sprint/sprint.pb.go @@ -23,6 +23,11 @@ import proto "github.com/gogo/protobuf/proto" import fmt "fmt" import math "math" +import ( + context "golang.org/x/net/context" + grpc "google.golang.org/grpc" +) + // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf @@ -43,6 +48,13 @@ func (m *AddSprintRequest) String() string { return proto.CompactText func (*AddSprintRequest) ProtoMessage() {} func (*AddSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{0} } +func (m *AddSprintRequest) GetName() string { + if m != nil { + return m.Name + } + return "" +} + type AddSprintResponse struct { Sprint *Sprint `protobuf:"bytes,1,opt,name=sprint" json:"sprint,omitempty"` ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` @@ -60,6 +72,13 @@ func (m *AddSprintResponse) GetSprint() *Sprint { return nil } +func (m *AddSprintResponse) GetErrMsg() string { + if m != nil { + return m.ErrMsg + } + return "" +} + type CloseSprintRequest struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` } @@ -69,6 +88,13 @@ func (m *CloseSprintRequest) String() string { return proto.CompactTe func (*CloseSprintRequest) ProtoMessage() {} func (*CloseSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{2} } +func (m *CloseSprintRequest) GetId() string { + if m != nil { + return m.Id + } + return "" +} + type CloseSprintResponse struct { ErrMsg string `protobuf:"bytes,1,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` } @@ -78,6 +104,13 @@ func (m *CloseSprintResponse) String() string { return proto.CompactT func (*CloseSprintResponse) ProtoMessage() {} func (*CloseSprintResponse) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{3} } +func (m *CloseSprintResponse) GetErrMsg() string { + if m != nil { + return m.ErrMsg + } + return "" +} + type GetSprintRequest struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` } @@ -87,6 +120,13 @@ func (m *GetSprintRequest) String() string { return proto.CompactText func (*GetSprintRequest) ProtoMessage() {} func (*GetSprintRequest) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{4} } +func (m *GetSprintRequest) GetId() string { + if m != nil { + return m.Id + } + return "" +} + type GetSprintResponse struct { Sprint *Sprint `protobuf:"bytes,1,opt,name=sprint" json:"sprint,omitempty"` ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` @@ -104,6 +144,13 @@ func (m *GetSprintResponse) GetSprint() *Sprint { return nil } +func (m *GetSprintResponse) GetErrMsg() string { + if m != nil { + return m.ErrMsg + } + return "" +} + type Sprint struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` CreatedAt uint32 `protobuf:"varint,2,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` @@ -115,6 +162,27 @@ func (m *Sprint) String() string { return proto.CompactTextString(m) func (*Sprint) ProtoMessage() {} func (*Sprint) Descriptor() ([]byte, []int) { return fileDescriptorSprint, []int{6} } +func (m *Sprint) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *Sprint) GetCreatedAt() uint32 { + if m != nil { + return m.CreatedAt + } + return 0 +} + +func (m *Sprint) GetName() string { + if m != nil { + return m.Name + } + return "" +} + func init() { proto.RegisterType((*AddSprintRequest)(nil), "sprint.AddSprintRequest") proto.RegisterType((*AddSprintResponse)(nil), "sprint.AddSprintResponse") @@ -125,6 +193,144 @@ func init() { proto.RegisterType((*Sprint)(nil), "sprint.Sprint") } +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// Client API for SprintService service + +type SprintServiceClient interface { + AddSprint(ctx context.Context, in *AddSprintRequest, opts ...grpc.CallOption) (*AddSprintResponse, error) + CloseSprint(ctx context.Context, in *CloseSprintRequest, opts ...grpc.CallOption) (*CloseSprintResponse, error) + GetSprint(ctx context.Context, in *GetSprintRequest, opts ...grpc.CallOption) (*GetSprintResponse, error) +} + +type sprintServiceClient struct { + cc *grpc.ClientConn +} + +func NewSprintServiceClient(cc *grpc.ClientConn) SprintServiceClient { + return &sprintServiceClient{cc} +} + +func (c *sprintServiceClient) AddSprint(ctx context.Context, in *AddSprintRequest, opts ...grpc.CallOption) (*AddSprintResponse, error) { + out := new(AddSprintResponse) + err := grpc.Invoke(ctx, "/sprint.SprintService/AddSprint", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *sprintServiceClient) CloseSprint(ctx context.Context, in *CloseSprintRequest, opts ...grpc.CallOption) (*CloseSprintResponse, error) { + out := new(CloseSprintResponse) + err := grpc.Invoke(ctx, "/sprint.SprintService/CloseSprint", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *sprintServiceClient) GetSprint(ctx context.Context, in *GetSprintRequest, opts ...grpc.CallOption) (*GetSprintResponse, error) { + out := new(GetSprintResponse) + err := grpc.Invoke(ctx, "/sprint.SprintService/GetSprint", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for SprintService service + +type SprintServiceServer interface { + AddSprint(context.Context, *AddSprintRequest) (*AddSprintResponse, error) + CloseSprint(context.Context, *CloseSprintRequest) (*CloseSprintResponse, error) + GetSprint(context.Context, *GetSprintRequest) (*GetSprintResponse, error) +} + +func RegisterSprintServiceServer(s *grpc.Server, srv SprintServiceServer) { + s.RegisterService(&_SprintService_serviceDesc, srv) +} + +func _SprintService_AddSprint_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AddSprintRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SprintServiceServer).AddSprint(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sprint.SprintService/AddSprint", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SprintServiceServer).AddSprint(ctx, req.(*AddSprintRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _SprintService_CloseSprint_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CloseSprintRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SprintServiceServer).CloseSprint(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sprint.SprintService/CloseSprint", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SprintServiceServer).CloseSprint(ctx, req.(*CloseSprintRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _SprintService_GetSprint_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetSprintRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SprintServiceServer).GetSprint(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sprint.SprintService/GetSprint", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SprintServiceServer).GetSprint(ctx, req.(*GetSprintRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _SprintService_serviceDesc = grpc.ServiceDesc{ + ServiceName: "sprint.SprintService", + HandlerType: (*SprintServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "AddSprint", + Handler: _SprintService_AddSprint_Handler, + }, + { + MethodName: "CloseSprint", + Handler: _SprintService_CloseSprint_Handler, + }, + { + MethodName: "GetSprint", + Handler: _SprintService_GetSprint_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "services/sprint/sprint.proto", +} + func init() { proto.RegisterFile("services/sprint/sprint.proto", fileDescriptorSprint) } var fileDescriptorSprint = []byte{ diff --git a/examples/go-kit/services/sprint/svc/service.go b/examples/go-kit/services/sprint/svc/service.go new file mode 100644 index 0000000..4080ee8 --- /dev/null +++ b/examples/go-kit/services/sprint/svc/service.go @@ -0,0 +1,27 @@ +package sprintsvc + +import ( + "fmt" + + "golang.org/x/net/context" + + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint" +) + +type Service struct{} + +func New() pb.SprintServiceServer { + return &Service{} +} + +func (svc *Service) AddSprint(ctx context.Context, in *pb.AddSprintRequest) (*pb.AddSprintResponse, error) { + return nil, fmt.Errorf("not implemented") +} + +func (svc *Service) CloseSprint(ctx context.Context, in *pb.CloseSprintRequest) (*pb.CloseSprintResponse, error) { + return nil, fmt.Errorf("not implemented") +} + +func (svc *Service) GetSprint(ctx context.Context, in *pb.GetSprintRequest) (*pb.GetSprintResponse, error) { + return nil, fmt.Errorf("not implemented") +} diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/endpoints/endpoints.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/endpoints/endpoints.go.tmpl index 654d705..8d1a4e6 100644 --- a/examples/go-kit/templates/{{.File.Package}}/gen/endpoints/endpoints.go.tmpl +++ b/examples/go-kit/templates/{{.File.Package}}/gen/endpoints/endpoints.go.tmpl @@ -23,7 +23,7 @@ func (e *Endpoints){{.Name}}(ctx context.Context, in *pb.{{.Name}}Request) (*pb. if err != nil { return &pb.{{.Name}}Response{ErrMsg: err.Error()}, err } - return out.(*pb.{{.Name}}Reply), err + return out.(*pb.{{.Name}}Response), err } {{end}} @@ -33,7 +33,7 @@ func Make{{.Name}}Endpoint(svc pb.{{$file.Package | title}}ServiceServer) endpoi req := request.(*pb.{{.Name}}Request) rep, err := svc.{{.Name}}(ctx, req) if err != nil { - return &pb.{{.Name}}Reply{ErrMsg: err.Error()}, err + return &pb.{{.Name}}Response{ErrMsg: err.Error()}, err } return rep, nil } diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl index 22ab6b3..3b58be8 100644 --- a/examples/go-kit/templates/{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl +++ b/examples/go-kit/templates/{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl @@ -1,4 +1,4 @@ -package {{.File.Package}}_transportgrpc +package {{.File.Package}}_grpctransport {{$file := .File}} @@ -8,7 +8,7 @@ import ( context "golang.org/x/net/context" pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}" grpctransport "github.com/go-kit/kit/transport/grpc" - endpoint "github.com/moul/protoc-gen-gotemplate/examples/go-kit/{{.File.Package}}/gen/endpoints" + endpoint "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/endpoints" ) // avoid import errors @@ -25,7 +25,7 @@ func MakeGRPCServer(ctx context.Context, endpoints endpoint.Endpoints) pb.{{.Fil endpoints.{{.Name}}Endpoint, decode{{.Name}}Request, encode{{.Name}}Response, - options, + options..., ), {{end}} {{end}} @@ -40,12 +40,12 @@ type grpcServer struct { } {{range .Service.Method}} -func (s *grpcServer) {{.Name}}(ctx context.Context, req *pb.{{.Name}}Request) (*pb.{{.Name}}Reply, error) { +func (s *grpcServer) {{.Name}}(ctx context.Context, req *pb.{{.Name}}Request) (*pb.{{.Name}}Response, error) { _, rep, err := s.{{.Name | lower}}.ServeGRPC(ctx, req) if err != nil { return nil, err } - return rep.(*pb.{{.Name}}Reply), nil + return rep.(*pb.{{.Name}}Response), nil } func decode{{.Name}}Request(ctx context.Context, grpcReq interface{}) (interface{}, error) { @@ -53,7 +53,7 @@ func decode{{.Name}}Request(ctx context.Context, grpcReq interface{}) (interface } func encode{{.Name}}Response(ctx context.Context, response interface{}) (interface{}, error) { - resp := response.(*pb.{{.Name}}Reply) + resp := response.(*pb.{{.Name}}Response) return resp, nil } {{end}} diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/transports/http/http.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/transports/http/http.go.tmpl index ece0496..dad4260 100644 --- a/examples/go-kit/templates/{{.File.Package}}/gen/transports/http/http.go.tmpl +++ b/examples/go-kit/templates/{{.File.Package}}/gen/transports/http/http.go.tmpl @@ -1,4 +1,4 @@ -package {{.File.Package}}_transporthttp +package {{.File.Package}}_httptransport {{$file := .File}} @@ -11,7 +11,7 @@ import ( pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}" gokit_endpoint "github.com/go-kit/kit/endpoint" httptransport "github.com/go-kit/kit/transport/http" - endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/{{.File.Package}}/gen/endpoints" + endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/endpoints" ) {{range .Service.Method}} @@ -21,7 +21,7 @@ func Make{{.Name}}Handler(ctx context.Context, svc pb.{{$file.Package | title}}S endpoint, decode{{.Name}}Request, encode{{.Name}}Response, - append([]httptransport.ServerOption{}, httptransport.ServerBefore(jwt.ToHTTPContext()))..., + []httptransport.ServerOption{}..., ) } From 701c12f866c86cdff7cf8d0e21fc80655f8af879 Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Tue, 13 Dec 2016 16:11:50 +0100 Subject: [PATCH 7/7] Move all generated code in the gen sub-directory --- examples/go-kit/Makefile | 4 ++++ examples/go-kit/main.go | 19 ++++++++++++++----- .../session/gen/endpoints/endpoints.go | 2 +- .../session/{session.pb.go => gen/pb/pb.go} | 0 .../session/gen/transports/grpc/grpc.go | 2 +- .../session/gen/transports/http/http.go | 2 +- .../services/session/{svc => }/service.go | 2 +- .../sprint/gen/endpoints/endpoints.go | 2 +- .../sprint/{sprint.pb.go => gen/pb/pb.go} | 0 .../sprint/gen/transports/grpc/grpc.go | 2 +- .../sprint/gen/transports/http/http.go | 2 +- .../services/sprint/{svc => }/service.go | 2 +- .../gen/endpoints/endpoints.go.tmpl | 2 +- .../gen/transports/grpc/grpc.go.tmpl | 2 +- .../gen/transports/http/http.go.tmpl | 2 +- 15 files changed, 29 insertions(+), 16 deletions(-) rename examples/go-kit/services/session/{session.pb.go => gen/pb/pb.go} (100%) rename examples/go-kit/services/session/{svc => }/service.go (96%) rename examples/go-kit/services/sprint/{sprint.pb.go => gen/pb/pb.go} (100%) rename examples/go-kit/services/sprint/{svc => }/service.go (97%) diff --git a/examples/go-kit/Makefile b/examples/go-kit/Makefile index ec0c065..2391b58 100644 --- a/examples/go-kit/Makefile +++ b/examples/go-kit/Makefile @@ -3,6 +3,8 @@ SOURCES := $(shell find . -name "*.proto" -not -path ./vendor/\*) TARGETS_GO := $(foreach source, $(SOURCES), $(source)_go) TARGETS_TMPL := $(foreach source, $(SOURCES), $(source)_tmpl) +service_name = $(word 2,$(subst /, ,$1)) + .PHONY: build build: server @@ -11,6 +13,8 @@ server: $(TARGETS_GO) $(TARGETS_TMPL) $(TARGETS_GO): %_go: protoc --gogo_out=plugins=grpc:. "$*" + @mkdir -p services/$(call service_name,$*)/gen/pb + @mv ./services/$(call service_name,$*)/$(call service_name,$*).pb.go ./services/$(call service_name,$*)/gen/pb/pb.go $(TARGETS_TMPL): %_tmpl: @mkdir -p $(dir $*)gen diff --git a/examples/go-kit/main.go b/examples/go-kit/main.go index 719e10a..c46bd1f 100644 --- a/examples/go-kit/main.go +++ b/examples/go-kit/main.go @@ -13,11 +13,17 @@ import ( "github.com/gorilla/handlers" "google.golang.org/grpc" - session_pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session" + session_svc "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session" session_endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints" + session_pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" session_grpctransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/transports/grpc" session_httptransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/transports/http" - sessionsvc "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/svc" + + sprint_svc "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint" + sprint_endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints" + sprint_pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" + sprint_grpctransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/transports/grpc" + sprint_httptransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/transports/http" ) func main() { @@ -34,15 +40,18 @@ func main() { // initialize services { - svc := sessionsvc.New() + svc := session_svc.New() endpoints := session_endpoints.MakeEndpoints(svc) srv := session_grpctransport.MakeGRPCServer(ctx, endpoints) session_pb.RegisterSessionServiceServer(s, srv) session_httptransport.RegisterHandlers(ctx, svc, mux, endpoints) } { - //svc := sprintsvc.New() - + svc := sprint_svc.New() + endpoints := sprint_endpoints.MakeEndpoints(svc) + srv := sprint_grpctransport.MakeGRPCServer(ctx, endpoints) + sprint_pb.RegisterSprintServiceServer(s, srv) + sprint_httptransport.RegisterHandlers(ctx, svc, mux, endpoints) } // start servers diff --git a/examples/go-kit/services/session/gen/endpoints/endpoints.go b/examples/go-kit/services/session/gen/endpoints/endpoints.go index eb1ee91..cc032f6 100644 --- a/examples/go-kit/services/session/gen/endpoints/endpoints.go +++ b/examples/go-kit/services/session/gen/endpoints/endpoints.go @@ -3,7 +3,7 @@ package session_endpoints import ( "fmt" "github.com/go-kit/kit/endpoint" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" context "golang.org/x/net/context" ) diff --git a/examples/go-kit/services/session/session.pb.go b/examples/go-kit/services/session/gen/pb/pb.go similarity index 100% rename from examples/go-kit/services/session/session.pb.go rename to examples/go-kit/services/session/gen/pb/pb.go diff --git a/examples/go-kit/services/session/gen/transports/grpc/grpc.go b/examples/go-kit/services/session/gen/transports/grpc/grpc.go index 45fd4e0..7053979 100644 --- a/examples/go-kit/services/session/gen/transports/grpc/grpc.go +++ b/examples/go-kit/services/session/gen/transports/grpc/grpc.go @@ -4,8 +4,8 @@ import ( "fmt" grpctransport "github.com/go-kit/kit/transport/grpc" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session" endpoint "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" context "golang.org/x/net/context" ) diff --git a/examples/go-kit/services/session/gen/transports/http/http.go b/examples/go-kit/services/session/gen/transports/http/http.go index 0bdbfeb..93aedb6 100644 --- a/examples/go-kit/services/session/gen/transports/http/http.go +++ b/examples/go-kit/services/session/gen/transports/http/http.go @@ -8,8 +8,8 @@ import ( gokit_endpoint "github.com/go-kit/kit/endpoint" httptransport "github.com/go-kit/kit/transport/http" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session" endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" ) func MakeLoginHandler(ctx context.Context, svc pb.SessionServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server { diff --git a/examples/go-kit/services/session/svc/service.go b/examples/go-kit/services/session/service.go similarity index 96% rename from examples/go-kit/services/session/svc/service.go rename to examples/go-kit/services/session/service.go index bbb9070..9e5134f 100644 --- a/examples/go-kit/services/session/svc/service.go +++ b/examples/go-kit/services/session/service.go @@ -5,7 +5,7 @@ import ( "golang.org/x/net/context" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb" ) type Service struct{} diff --git a/examples/go-kit/services/sprint/gen/endpoints/endpoints.go b/examples/go-kit/services/sprint/gen/endpoints/endpoints.go index bcad549..56a0fe5 100644 --- a/examples/go-kit/services/sprint/gen/endpoints/endpoints.go +++ b/examples/go-kit/services/sprint/gen/endpoints/endpoints.go @@ -3,7 +3,7 @@ package sprint_endpoints import ( "fmt" "github.com/go-kit/kit/endpoint" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" context "golang.org/x/net/context" ) diff --git a/examples/go-kit/services/sprint/sprint.pb.go b/examples/go-kit/services/sprint/gen/pb/pb.go similarity index 100% rename from examples/go-kit/services/sprint/sprint.pb.go rename to examples/go-kit/services/sprint/gen/pb/pb.go diff --git a/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go b/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go index ca83972..ce3c15f 100644 --- a/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go +++ b/examples/go-kit/services/sprint/gen/transports/grpc/grpc.go @@ -4,8 +4,8 @@ import ( "fmt" grpctransport "github.com/go-kit/kit/transport/grpc" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint" endpoint "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" context "golang.org/x/net/context" ) diff --git a/examples/go-kit/services/sprint/gen/transports/http/http.go b/examples/go-kit/services/sprint/gen/transports/http/http.go index 492ead0..5d76962 100644 --- a/examples/go-kit/services/sprint/gen/transports/http/http.go +++ b/examples/go-kit/services/sprint/gen/transports/http/http.go @@ -8,8 +8,8 @@ import ( gokit_endpoint "github.com/go-kit/kit/endpoint" httptransport "github.com/go-kit/kit/transport/http" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint" endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" ) func MakeAddSprintHandler(ctx context.Context, svc pb.SprintServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server { diff --git a/examples/go-kit/services/sprint/svc/service.go b/examples/go-kit/services/sprint/service.go similarity index 97% rename from examples/go-kit/services/sprint/svc/service.go rename to examples/go-kit/services/sprint/service.go index 4080ee8..6b26f7c 100644 --- a/examples/go-kit/services/sprint/svc/service.go +++ b/examples/go-kit/services/sprint/service.go @@ -5,7 +5,7 @@ import ( "golang.org/x/net/context" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb" ) type Service struct{} diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/endpoints/endpoints.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/endpoints/endpoints.go.tmpl index 8d1a4e6..557ef4a 100644 --- a/examples/go-kit/templates/{{.File.Package}}/gen/endpoints/endpoints.go.tmpl +++ b/examples/go-kit/templates/{{.File.Package}}/gen/endpoints/endpoints.go.tmpl @@ -5,7 +5,7 @@ package {{.File.Package}}_endpoints import ( "fmt" context "golang.org/x/net/context" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/pb" "github.com/go-kit/kit/endpoint" ) diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl index 3b58be8..41dc7d4 100644 --- a/examples/go-kit/templates/{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl +++ b/examples/go-kit/templates/{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl @@ -6,7 +6,7 @@ import ( "fmt" context "golang.org/x/net/context" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/pb" grpctransport "github.com/go-kit/kit/transport/grpc" endpoint "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/endpoints" ) diff --git a/examples/go-kit/templates/{{.File.Package}}/gen/transports/http/http.go.tmpl b/examples/go-kit/templates/{{.File.Package}}/gen/transports/http/http.go.tmpl index dad4260..8adc0f3 100644 --- a/examples/go-kit/templates/{{.File.Package}}/gen/transports/http/http.go.tmpl +++ b/examples/go-kit/templates/{{.File.Package}}/gen/transports/http/http.go.tmpl @@ -8,7 +8,7 @@ import ( "encoding/json" context "golang.org/x/net/context" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}" + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/pb" gokit_endpoint "github.com/go-kit/kit/endpoint" httptransport "github.com/go-kit/kit/transport/http" endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/endpoints"