From df709b52ac769da282f042228dbc479dbdd6c4e9 Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Thu, 15 Dec 2016 16:28:04 +0100 Subject: [PATCH] Refactor the go-kit templates to make imports generic --- .../{{.File.Package}}/gen/endpoints/endpoints.go.tmpl | 5 +++-- .../{{.File.Package}}/gen/transports/grpc/grpc.go.tmpl | 6 +++--- .../{{.File.Package}}/gen/transports/http/http.go.tmpl | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) 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 557ef4a..cb3b769 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 @@ -4,8 +4,9 @@ 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}}/gen/pb" + pb "{{cat .GoPWD "/" .DestinationDir | nospace | clean}}/pb" "github.com/go-kit/kit/endpoint" ) @@ -29,7 +30,7 @@ func (e *Endpoints){{.Name}}(ctx context.Context, in *pb.{{.Name}}Request) (*pb. {{range .Service.Method}} func Make{{.Name}}Endpoint(svc pb.{{$file.Package | title}}ServiceServer) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (interface{}, error) { + return func(ctx context.Context, request interface{}) (interface{}, error) { req := request.(*pb.{{.Name}}Request) rep, err := svc.{{.Name}}(ctx, req) if err != 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 41dc7d4..14e8ca4 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,15 +6,15 @@ import ( "fmt" context "golang.org/x/net/context" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/pb" + pb "{{cat .GoPWD "/" .DestinationDir | nospace | clean}}/pb" + endpoints "{{cat .GoPWD "/" .DestinationDir | nospace | clean}}/endpoints" grpctransport "github.com/go-kit/kit/transport/grpc" - endpoint "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/endpoints" ) // avoid import errors var _ = fmt.Errorf -func MakeGRPCServer(ctx context.Context, endpoints endpoint.Endpoints) pb.{{.File.Package | title}}ServiceServer { +func MakeGRPCServer(ctx context.Context, endpoints endpoints.Endpoints) pb.{{.File.Package | title}}ServiceServer { options := []grpctransport.ServerOption{} return &grpcServer{ {{range .Service.Method}} 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 8adc0f3..a57eb6b 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,10 +8,10 @@ import ( "encoding/json" context "golang.org/x/net/context" - pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/{{.File.Package}}/gen/pb" + pb "{{cat .GoPWD "/" .DestinationDir | nospace | clean}}/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" + httptransport "github.com/go-kit/kit/transport/http" + endpoints "{{cat .GoPWD "/" .DestinationDir | nospace | clean}}/endpoints" ) {{range .Service.Method}}