Regenerate boilerplate
This commit is contained in:
parent
f5d97d64c7
commit
91e9114c24
44
examples/go-kit/services/session/gen/client/grpc/client.go
Normal file
44
examples/go-kit/services/session/gen/client/grpc/client.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package session_clientgrpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
jwt "github.com/go-kit/kit/auth/jwt"
|
||||||
|
"github.com/go-kit/kit/endpoint"
|
||||||
|
"github.com/go-kit/kit/log"
|
||||||
|
grpctransport "github.com/go-kit/kit/transport/grpc"
|
||||||
|
context "golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
|
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 New(conn *grpc.ClientConn, logger log.Logger) pb.SessionServiceServer {
|
||||||
|
|
||||||
|
var loginEndpoint endpoint.Endpoint
|
||||||
|
{
|
||||||
|
loginEndpoint = grpctransport.NewClient(
|
||||||
|
conn,
|
||||||
|
"session.SessionService",
|
||||||
|
"Login",
|
||||||
|
EncodeLoginRequest,
|
||||||
|
DecodeLoginResponse,
|
||||||
|
pb.LoginResponse{},
|
||||||
|
append([]grpctransport.ClientOption{}, grpctransport.ClientBefore(jwt.FromGRPCContext()))...,
|
||||||
|
).Endpoint()
|
||||||
|
}
|
||||||
|
|
||||||
|
return &endpoints.Endpoints{
|
||||||
|
|
||||||
|
LoginEndpoint: loginEndpoint,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func EncodeLoginRequest(_ context.Context, request interface{}) (interface{}, error) {
|
||||||
|
req := request.(*pb.LoginRequest)
|
||||||
|
return req, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DecodeLoginResponse(_ context.Context, grpcResponse interface{}) (interface{}, error) {
|
||||||
|
response := grpcResponse.(*pb.LoginResponse)
|
||||||
|
return response, nil
|
||||||
|
}
|
@ -10,6 +10,8 @@ import (
|
|||||||
|
|
||||||
var _ = fmt.Errorf
|
var _ = fmt.Errorf
|
||||||
|
|
||||||
|
type StreamEndpoint func(server interface{}, req interface{}) (err error)
|
||||||
|
|
||||||
type Endpoints struct {
|
type Endpoints struct {
|
||||||
LoginEndpoint endpoint.Endpoint
|
LoginEndpoint endpoint.Endpoint
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
grpctransport "github.com/go-kit/kit/transport/grpc"
|
grpctransport "github.com/go-kit/kit/transport/grpc"
|
||||||
|
context "golang.org/x/net/context"
|
||||||
|
|
||||||
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints"
|
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"
|
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/pb"
|
||||||
context "golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// avoid import errors
|
// avoid import errors
|
||||||
@ -19,7 +20,7 @@ func MakeGRPCServer(ctx context.Context, endpoints endpoints.Endpoints) pb.Sessi
|
|||||||
login: grpctransport.NewServer(
|
login: grpctransport.NewServer(
|
||||||
ctx,
|
ctx,
|
||||||
endpoints.LoginEndpoint,
|
endpoints.LoginEndpoint,
|
||||||
decodeLoginRequest,
|
decodeRequest,
|
||||||
encodeLoginResponse,
|
encodeLoginResponse,
|
||||||
options...,
|
options...,
|
||||||
),
|
),
|
||||||
@ -38,11 +39,26 @@ func (s *grpcServer) Login(ctx context.Context, req *pb.LoginRequest) (*pb.Login
|
|||||||
return rep.(*pb.LoginResponse), nil
|
return rep.(*pb.LoginResponse), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeLoginRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) {
|
|
||||||
return grpcReq, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeLoginResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
func encodeLoginResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
||||||
resp := response.(*pb.LoginResponse)
|
resp := response.(*pb.LoginResponse)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func decodeRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) {
|
||||||
|
return grpcReq, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type streamHandler interface {
|
||||||
|
Do(server interface{}, req interface{}) (err error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type server struct {
|
||||||
|
e endpoints.StreamEndpoint
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s server) Do(server interface{}, req interface{}) (err error) {
|
||||||
|
if err := s.e(server, req); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -17,7 +17,7 @@ func MakeLoginHandler(ctx context.Context, svc pb.SessionServiceServer, endpoint
|
|||||||
ctx,
|
ctx,
|
||||||
endpoint,
|
endpoint,
|
||||||
decodeLoginRequest,
|
decodeLoginRequest,
|
||||||
encodeLoginResponse,
|
encodeResponse,
|
||||||
[]httptransport.ServerOption{}...,
|
[]httptransport.ServerOption{}...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -30,7 +30,7 @@ func decodeLoginRequest(ctx context.Context, r *http.Request) (interface{}, erro
|
|||||||
return &req, nil
|
return &req, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeLoginResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error {
|
func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error {
|
||||||
return json.NewEncoder(w).Encode(response)
|
return json.NewEncoder(w).Encode(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
94
examples/go-kit/services/sprint/gen/client/grpc/client.go
Normal file
94
examples/go-kit/services/sprint/gen/client/grpc/client.go
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
package sprint_clientgrpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
jwt "github.com/go-kit/kit/auth/jwt"
|
||||||
|
"github.com/go-kit/kit/endpoint"
|
||||||
|
"github.com/go-kit/kit/log"
|
||||||
|
grpctransport "github.com/go-kit/kit/transport/grpc"
|
||||||
|
context "golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
|
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 New(conn *grpc.ClientConn, logger log.Logger) pb.SprintServiceServer {
|
||||||
|
|
||||||
|
var addsprintEndpoint endpoint.Endpoint
|
||||||
|
{
|
||||||
|
addsprintEndpoint = grpctransport.NewClient(
|
||||||
|
conn,
|
||||||
|
"sprint.SprintService",
|
||||||
|
"AddSprint",
|
||||||
|
EncodeAddSprintRequest,
|
||||||
|
DecodeAddSprintResponse,
|
||||||
|
pb.AddSprintResponse{},
|
||||||
|
append([]grpctransport.ClientOption{}, grpctransport.ClientBefore(jwt.FromGRPCContext()))...,
|
||||||
|
).Endpoint()
|
||||||
|
}
|
||||||
|
|
||||||
|
var closesprintEndpoint endpoint.Endpoint
|
||||||
|
{
|
||||||
|
closesprintEndpoint = grpctransport.NewClient(
|
||||||
|
conn,
|
||||||
|
"sprint.SprintService",
|
||||||
|
"CloseSprint",
|
||||||
|
EncodeCloseSprintRequest,
|
||||||
|
DecodeCloseSprintResponse,
|
||||||
|
pb.CloseSprintResponse{},
|
||||||
|
append([]grpctransport.ClientOption{}, grpctransport.ClientBefore(jwt.FromGRPCContext()))...,
|
||||||
|
).Endpoint()
|
||||||
|
}
|
||||||
|
|
||||||
|
var getsprintEndpoint endpoint.Endpoint
|
||||||
|
{
|
||||||
|
getsprintEndpoint = grpctransport.NewClient(
|
||||||
|
conn,
|
||||||
|
"sprint.SprintService",
|
||||||
|
"GetSprint",
|
||||||
|
EncodeGetSprintRequest,
|
||||||
|
DecodeGetSprintResponse,
|
||||||
|
pb.GetSprintResponse{},
|
||||||
|
append([]grpctransport.ClientOption{}, grpctransport.ClientBefore(jwt.FromGRPCContext()))...,
|
||||||
|
).Endpoint()
|
||||||
|
}
|
||||||
|
|
||||||
|
return &endpoints.Endpoints{
|
||||||
|
|
||||||
|
AddSprintEndpoint: addsprintEndpoint,
|
||||||
|
|
||||||
|
CloseSprintEndpoint: closesprintEndpoint,
|
||||||
|
|
||||||
|
GetSprintEndpoint: getsprintEndpoint,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func EncodeAddSprintRequest(_ context.Context, request interface{}) (interface{}, error) {
|
||||||
|
req := request.(*pb.AddSprintRequest)
|
||||||
|
return req, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DecodeAddSprintResponse(_ context.Context, grpcResponse interface{}) (interface{}, error) {
|
||||||
|
response := grpcResponse.(*pb.AddSprintResponse)
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func EncodeCloseSprintRequest(_ context.Context, request interface{}) (interface{}, error) {
|
||||||
|
req := request.(*pb.CloseSprintRequest)
|
||||||
|
return req, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DecodeCloseSprintResponse(_ context.Context, grpcResponse interface{}) (interface{}, error) {
|
||||||
|
response := grpcResponse.(*pb.CloseSprintResponse)
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func EncodeGetSprintRequest(_ context.Context, request interface{}) (interface{}, error) {
|
||||||
|
req := request.(*pb.GetSprintRequest)
|
||||||
|
return req, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DecodeGetSprintResponse(_ context.Context, grpcResponse interface{}) (interface{}, error) {
|
||||||
|
response := grpcResponse.(*pb.GetSprintResponse)
|
||||||
|
return response, nil
|
||||||
|
}
|
@ -10,6 +10,8 @@ import (
|
|||||||
|
|
||||||
var _ = fmt.Errorf
|
var _ = fmt.Errorf
|
||||||
|
|
||||||
|
type StreamEndpoint func(server interface{}, req interface{}) (err error)
|
||||||
|
|
||||||
type Endpoints struct {
|
type Endpoints struct {
|
||||||
AddSprintEndpoint endpoint.Endpoint
|
AddSprintEndpoint endpoint.Endpoint
|
||||||
|
|
||||||
|
@ -4,9 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
grpctransport "github.com/go-kit/kit/transport/grpc"
|
grpctransport "github.com/go-kit/kit/transport/grpc"
|
||||||
|
context "golang.org/x/net/context"
|
||||||
|
|
||||||
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/endpoints"
|
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"
|
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/sprint/gen/pb"
|
||||||
context "golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// avoid import errors
|
// avoid import errors
|
||||||
@ -19,7 +20,7 @@ func MakeGRPCServer(ctx context.Context, endpoints endpoints.Endpoints) pb.Sprin
|
|||||||
addsprint: grpctransport.NewServer(
|
addsprint: grpctransport.NewServer(
|
||||||
ctx,
|
ctx,
|
||||||
endpoints.AddSprintEndpoint,
|
endpoints.AddSprintEndpoint,
|
||||||
decodeAddSprintRequest,
|
decodeRequest,
|
||||||
encodeAddSprintResponse,
|
encodeAddSprintResponse,
|
||||||
options...,
|
options...,
|
||||||
),
|
),
|
||||||
@ -27,7 +28,7 @@ func MakeGRPCServer(ctx context.Context, endpoints endpoints.Endpoints) pb.Sprin
|
|||||||
closesprint: grpctransport.NewServer(
|
closesprint: grpctransport.NewServer(
|
||||||
ctx,
|
ctx,
|
||||||
endpoints.CloseSprintEndpoint,
|
endpoints.CloseSprintEndpoint,
|
||||||
decodeCloseSprintRequest,
|
decodeRequest,
|
||||||
encodeCloseSprintResponse,
|
encodeCloseSprintResponse,
|
||||||
options...,
|
options...,
|
||||||
),
|
),
|
||||||
@ -35,7 +36,7 @@ func MakeGRPCServer(ctx context.Context, endpoints endpoints.Endpoints) pb.Sprin
|
|||||||
getsprint: grpctransport.NewServer(
|
getsprint: grpctransport.NewServer(
|
||||||
ctx,
|
ctx,
|
||||||
endpoints.GetSprintEndpoint,
|
endpoints.GetSprintEndpoint,
|
||||||
decodeGetSprintRequest,
|
decodeRequest,
|
||||||
encodeGetSprintResponse,
|
encodeGetSprintResponse,
|
||||||
options...,
|
options...,
|
||||||
),
|
),
|
||||||
@ -58,10 +59,6 @@ func (s *grpcServer) AddSprint(ctx context.Context, req *pb.AddSprintRequest) (*
|
|||||||
return rep.(*pb.AddSprintResponse), nil
|
return rep.(*pb.AddSprintResponse), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeAddSprintRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) {
|
|
||||||
return grpcReq, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeAddSprintResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
func encodeAddSprintResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
||||||
resp := response.(*pb.AddSprintResponse)
|
resp := response.(*pb.AddSprintResponse)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
@ -75,10 +72,6 @@ func (s *grpcServer) CloseSprint(ctx context.Context, req *pb.CloseSprintRequest
|
|||||||
return rep.(*pb.CloseSprintResponse), nil
|
return rep.(*pb.CloseSprintResponse), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeCloseSprintRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) {
|
|
||||||
return grpcReq, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeCloseSprintResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
func encodeCloseSprintResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
||||||
resp := response.(*pb.CloseSprintResponse)
|
resp := response.(*pb.CloseSprintResponse)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
@ -92,11 +85,26 @@ func (s *grpcServer) GetSprint(ctx context.Context, req *pb.GetSprintRequest) (*
|
|||||||
return rep.(*pb.GetSprintResponse), nil
|
return rep.(*pb.GetSprintResponse), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeGetSprintRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) {
|
|
||||||
return grpcReq, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeGetSprintResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
func encodeGetSprintResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
||||||
resp := response.(*pb.GetSprintResponse)
|
resp := response.(*pb.GetSprintResponse)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func decodeRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) {
|
||||||
|
return grpcReq, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type streamHandler interface {
|
||||||
|
Do(server interface{}, req interface{}) (err error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type server struct {
|
||||||
|
e endpoints.StreamEndpoint
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s server) Do(server interface{}, req interface{}) (err error) {
|
||||||
|
if err := s.e(server, req); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -17,7 +17,7 @@ func MakeAddSprintHandler(ctx context.Context, svc pb.SprintServiceServer, endpo
|
|||||||
ctx,
|
ctx,
|
||||||
endpoint,
|
endpoint,
|
||||||
decodeAddSprintRequest,
|
decodeAddSprintRequest,
|
||||||
encodeAddSprintResponse,
|
encodeResponse,
|
||||||
[]httptransport.ServerOption{}...,
|
[]httptransport.ServerOption{}...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -30,16 +30,12 @@ func decodeAddSprintRequest(ctx context.Context, r *http.Request) (interface{},
|
|||||||
return &req, nil
|
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 {
|
func MakeCloseSprintHandler(ctx context.Context, svc pb.SprintServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server {
|
||||||
return httptransport.NewServer(
|
return httptransport.NewServer(
|
||||||
ctx,
|
ctx,
|
||||||
endpoint,
|
endpoint,
|
||||||
decodeCloseSprintRequest,
|
decodeCloseSprintRequest,
|
||||||
encodeCloseSprintResponse,
|
encodeResponse,
|
||||||
[]httptransport.ServerOption{}...,
|
[]httptransport.ServerOption{}...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -52,16 +48,12 @@ func decodeCloseSprintRequest(ctx context.Context, r *http.Request) (interface{}
|
|||||||
return &req, nil
|
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 {
|
func MakeGetSprintHandler(ctx context.Context, svc pb.SprintServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server {
|
||||||
return httptransport.NewServer(
|
return httptransport.NewServer(
|
||||||
ctx,
|
ctx,
|
||||||
endpoint,
|
endpoint,
|
||||||
decodeGetSprintRequest,
|
decodeGetSprintRequest,
|
||||||
encodeGetSprintResponse,
|
encodeResponse,
|
||||||
[]httptransport.ServerOption{}...,
|
[]httptransport.ServerOption{}...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -74,7 +66,7 @@ func decodeGetSprintRequest(ctx context.Context, r *http.Request) (interface{},
|
|||||||
return &req, nil
|
return &req, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeGetSprintResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error {
|
func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error {
|
||||||
return json.NewEncoder(w).Encode(response)
|
return json.NewEncoder(w).Encode(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
69
examples/go-kit/services/user/gen/client/grpc/client.go
Normal file
69
examples/go-kit/services/user/gen/client/grpc/client.go
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
package user_clientgrpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
jwt "github.com/go-kit/kit/auth/jwt"
|
||||||
|
"github.com/go-kit/kit/endpoint"
|
||||||
|
"github.com/go-kit/kit/log"
|
||||||
|
grpctransport "github.com/go-kit/kit/transport/grpc"
|
||||||
|
context "golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
|
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints"
|
||||||
|
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
func New(conn *grpc.ClientConn, logger log.Logger) pb.UserServiceServer {
|
||||||
|
|
||||||
|
var createuserEndpoint endpoint.Endpoint
|
||||||
|
{
|
||||||
|
createuserEndpoint = grpctransport.NewClient(
|
||||||
|
conn,
|
||||||
|
"user.UserService",
|
||||||
|
"CreateUser",
|
||||||
|
EncodeCreateUserRequest,
|
||||||
|
DecodeCreateUserResponse,
|
||||||
|
pb.CreateUserResponse{},
|
||||||
|
append([]grpctransport.ClientOption{}, grpctransport.ClientBefore(jwt.FromGRPCContext()))...,
|
||||||
|
).Endpoint()
|
||||||
|
}
|
||||||
|
|
||||||
|
var getuserEndpoint endpoint.Endpoint
|
||||||
|
{
|
||||||
|
getuserEndpoint = grpctransport.NewClient(
|
||||||
|
conn,
|
||||||
|
"user.UserService",
|
||||||
|
"GetUser",
|
||||||
|
EncodeGetUserRequest,
|
||||||
|
DecodeGetUserResponse,
|
||||||
|
pb.GetUserResponse{},
|
||||||
|
append([]grpctransport.ClientOption{}, grpctransport.ClientBefore(jwt.FromGRPCContext()))...,
|
||||||
|
).Endpoint()
|
||||||
|
}
|
||||||
|
|
||||||
|
return &endpoints.Endpoints{
|
||||||
|
|
||||||
|
CreateUserEndpoint: createuserEndpoint,
|
||||||
|
|
||||||
|
GetUserEndpoint: getuserEndpoint,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func EncodeCreateUserRequest(_ context.Context, request interface{}) (interface{}, error) {
|
||||||
|
req := request.(*pb.CreateUserRequest)
|
||||||
|
return req, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DecodeCreateUserResponse(_ context.Context, grpcResponse interface{}) (interface{}, error) {
|
||||||
|
response := grpcResponse.(*pb.CreateUserResponse)
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func EncodeGetUserRequest(_ context.Context, request interface{}) (interface{}, error) {
|
||||||
|
req := request.(*pb.GetUserRequest)
|
||||||
|
return req, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DecodeGetUserResponse(_ context.Context, grpcResponse interface{}) (interface{}, error) {
|
||||||
|
response := grpcResponse.(*pb.GetUserResponse)
|
||||||
|
return response, nil
|
||||||
|
}
|
@ -10,6 +10,8 @@ import (
|
|||||||
|
|
||||||
var _ = fmt.Errorf
|
var _ = fmt.Errorf
|
||||||
|
|
||||||
|
type StreamEndpoint func(server interface{}, req interface{}) (err error)
|
||||||
|
|
||||||
type Endpoints struct {
|
type Endpoints struct {
|
||||||
CreateUserEndpoint endpoint.Endpoint
|
CreateUserEndpoint endpoint.Endpoint
|
||||||
|
|
||||||
|
@ -4,9 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
grpctransport "github.com/go-kit/kit/transport/grpc"
|
grpctransport "github.com/go-kit/kit/transport/grpc"
|
||||||
|
context "golang.org/x/net/context"
|
||||||
|
|
||||||
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints"
|
endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/endpoints"
|
||||||
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb"
|
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/user/gen/pb"
|
||||||
context "golang.org/x/net/context"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// avoid import errors
|
// avoid import errors
|
||||||
@ -19,7 +20,7 @@ func MakeGRPCServer(ctx context.Context, endpoints endpoints.Endpoints) pb.UserS
|
|||||||
createuser: grpctransport.NewServer(
|
createuser: grpctransport.NewServer(
|
||||||
ctx,
|
ctx,
|
||||||
endpoints.CreateUserEndpoint,
|
endpoints.CreateUserEndpoint,
|
||||||
decodeCreateUserRequest,
|
decodeRequest,
|
||||||
encodeCreateUserResponse,
|
encodeCreateUserResponse,
|
||||||
options...,
|
options...,
|
||||||
),
|
),
|
||||||
@ -27,7 +28,7 @@ func MakeGRPCServer(ctx context.Context, endpoints endpoints.Endpoints) pb.UserS
|
|||||||
getuser: grpctransport.NewServer(
|
getuser: grpctransport.NewServer(
|
||||||
ctx,
|
ctx,
|
||||||
endpoints.GetUserEndpoint,
|
endpoints.GetUserEndpoint,
|
||||||
decodeGetUserRequest,
|
decodeRequest,
|
||||||
encodeGetUserResponse,
|
encodeGetUserResponse,
|
||||||
options...,
|
options...,
|
||||||
),
|
),
|
||||||
@ -48,10 +49,6 @@ func (s *grpcServer) CreateUser(ctx context.Context, req *pb.CreateUserRequest)
|
|||||||
return rep.(*pb.CreateUserResponse), nil
|
return rep.(*pb.CreateUserResponse), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeCreateUserRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) {
|
|
||||||
return grpcReq, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeCreateUserResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
func encodeCreateUserResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
||||||
resp := response.(*pb.CreateUserResponse)
|
resp := response.(*pb.CreateUserResponse)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
@ -65,11 +62,26 @@ func (s *grpcServer) GetUser(ctx context.Context, req *pb.GetUserRequest) (*pb.G
|
|||||||
return rep.(*pb.GetUserResponse), nil
|
return rep.(*pb.GetUserResponse), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeGetUserRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) {
|
|
||||||
return grpcReq, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeGetUserResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
func encodeGetUserResponse(ctx context.Context, response interface{}) (interface{}, error) {
|
||||||
resp := response.(*pb.GetUserResponse)
|
resp := response.(*pb.GetUserResponse)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func decodeRequest(ctx context.Context, grpcReq interface{}) (interface{}, error) {
|
||||||
|
return grpcReq, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type streamHandler interface {
|
||||||
|
Do(server interface{}, req interface{}) (err error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type server struct {
|
||||||
|
e endpoints.StreamEndpoint
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s server) Do(server interface{}, req interface{}) (err error) {
|
||||||
|
if err := s.e(server, req); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -17,7 +17,7 @@ func MakeCreateUserHandler(ctx context.Context, svc pb.UserServiceServer, endpoi
|
|||||||
ctx,
|
ctx,
|
||||||
endpoint,
|
endpoint,
|
||||||
decodeCreateUserRequest,
|
decodeCreateUserRequest,
|
||||||
encodeCreateUserResponse,
|
encodeResponse,
|
||||||
[]httptransport.ServerOption{}...,
|
[]httptransport.ServerOption{}...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -30,16 +30,12 @@ func decodeCreateUserRequest(ctx context.Context, r *http.Request) (interface{},
|
|||||||
return &req, nil
|
return &req, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeCreateUserResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error {
|
|
||||||
return json.NewEncoder(w).Encode(response)
|
|
||||||
}
|
|
||||||
|
|
||||||
func MakeGetUserHandler(ctx context.Context, svc pb.UserServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server {
|
func MakeGetUserHandler(ctx context.Context, svc pb.UserServiceServer, endpoint gokit_endpoint.Endpoint) *httptransport.Server {
|
||||||
return httptransport.NewServer(
|
return httptransport.NewServer(
|
||||||
ctx,
|
ctx,
|
||||||
endpoint,
|
endpoint,
|
||||||
decodeGetUserRequest,
|
decodeGetUserRequest,
|
||||||
encodeGetUserResponse,
|
encodeResponse,
|
||||||
[]httptransport.ServerOption{}...,
|
[]httptransport.ServerOption{}...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -52,7 +48,7 @@ func decodeGetUserRequest(ctx context.Context, r *http.Request) (interface{}, er
|
|||||||
return &req, nil
|
return &req, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeGetUserResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error {
|
func encodeResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error {
|
||||||
return json.NewEncoder(w).Encode(response)
|
return json.NewEncoder(w).Encode(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user