Add entrypoint
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
@@ -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{}...,
|
||||
)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user