diff --git a/examples/go-kit/main.go b/examples/go-kit/main.go index c46bd1f..32c03a6 100644 --- a/examples/go-kit/main.go +++ b/examples/go-kit/main.go @@ -24,6 +24,12 @@ import ( 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" + + user_svc "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user" + user_endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints" + user_pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb" + user_grpctransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/transports/grpc" + user_httptransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/transports/http" ) func main() { @@ -53,6 +59,13 @@ func main() { sprint_pb.RegisterSprintServiceServer(s, srv) sprint_httptransport.RegisterHandlers(ctx, svc, mux, endpoints) } + { + svc := user_svc.New() + endpoints := user_endpoints.MakeEndpoints(svc) + srv := user_grpctransport.MakeGRPCServer(ctx, endpoints) + user_pb.RegisterUserServiceServer(s, srv) + user_httptransport.RegisterHandlers(ctx, svc, mux, endpoints) + } // start servers go func() { diff --git a/examples/go-kit/services/user/service.go b/examples/go-kit/services/user/service.go new file mode 100644 index 0000000..b4bb7f1 --- /dev/null +++ b/examples/go-kit/services/user/service.go @@ -0,0 +1,21 @@ +package usersvc + +import ( + "fmt" + + "golang.org/x/net/context" + + pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb" +) + +type Service struct{} + +func New() pb.UserServiceServer { return &Service{} } + +func (svc *Service) CreateUser(ctx context.Context, in *pb.CreateUserRequest) (*pb.CreateUserResponse, error) { + return nil, fmt.Errorf("not implemented") +} + +func (svc *Service) GetUser(ctx context.Context, in *pb.GetUserRequest) (*pb.GetUserResponse, error) { + return nil, fmt.Errorf("not implemented") +} diff --git a/examples/go-kit/services/user/user.proto b/examples/go-kit/services/user/user.proto new file mode 100644 index 0000000..f74c299 --- /dev/null +++ b/examples/go-kit/services/user/user.proto @@ -0,0 +1,29 @@ +syntax = "proto3"; + +package user; + +service UserService { + rpc CreateUser(CreateUserRequest) returns (CreateUserResponse) {} + rpc GetUser(GetUserRequest) returns (GetUserResponse) {} +} + +message CreateUserRequest { + string name = 1; +} +message CreateUserResponse { + User user = 1; + string err_msg = 2; +} + +message GetUserRequest { + string id = 1; +} +message GetUserResponse { + User user = 1; + string err_msg = 2; +} + +message User { + string id = 1; + string name = 2; +} \ No newline at end of file