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"