Add entrypoint

This commit is contained in:
Manfred Touron
2016-12-13 16:03:16 +01:00
parent f62940ac4c
commit d748878896
18 changed files with 541 additions and 305 deletions

View File

@@ -20,7 +20,7 @@ func (e *Endpoints) Login(ctx context.Context, in *pb.LoginRequest) (*pb.LoginRe
if err != nil {
return &pb.LoginResponse{ErrMsg: err.Error()}, err
}
return out.(*pb.LoginReply), err
return out.(*pb.LoginResponse), err
}
func (e *Endpoints) Logout(ctx context.Context, in *pb.LogoutRequest) (*pb.LogoutResponse, error) {
@@ -28,7 +28,7 @@ func (e *Endpoints) Logout(ctx context.Context, in *pb.LogoutRequest) (*pb.Logou
if err != nil {
return &pb.LogoutResponse{ErrMsg: err.Error()}, err
}
return out.(*pb.LogoutReply), err
return out.(*pb.LogoutResponse), err
}
func MakeLoginEndpoint(svc pb.SessionServiceServer) endpoint.Endpoint {
@@ -36,7 +36,7 @@ func MakeLoginEndpoint(svc pb.SessionServiceServer) endpoint.Endpoint {
req := request.(*pb.LoginRequest)
rep, err := svc.Login(ctx, req)
if err != nil {
return &pb.LoginReply{ErrMsg: err.Error()}, err
return &pb.LoginResponse{ErrMsg: err.Error()}, err
}
return rep, nil
}
@@ -47,7 +47,7 @@ func MakeLogoutEndpoint(svc pb.SessionServiceServer) endpoint.Endpoint {
req := request.(*pb.LogoutRequest)
rep, err := svc.Logout(ctx, req)
if err != nil {
return &pb.LogoutReply{ErrMsg: err.Error()}, err
return &pb.LogoutResponse{ErrMsg: err.Error()}, err
}
return rep, nil
}

View File

@@ -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
}

View File

@@ -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{}...,
)
}

View File

@@ -1,98 +0,0 @@
// Code generated by protoc-gen-gogo.
// source: services/session/session.proto
// DO NOT EDIT!
/*
Package session is a generated protocol buffer package.
It is generated from these files:
services/session/session.proto
It has these top-level messages:
LoginRequest
LoginResponse
LogoutRequest
LogoutResponse
*/
package session
import proto "github.com/gogo/protobuf/proto"
import fmt "fmt"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package
type LoginRequest struct {
Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"`
}
func (m *LoginRequest) Reset() { *m = LoginRequest{} }
func (m *LoginRequest) String() string { return proto.CompactTextString(m) }
func (*LoginRequest) ProtoMessage() {}
func (*LoginRequest) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{0} }
type LoginResponse struct {
Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"`
ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"`
}
func (m *LoginResponse) Reset() { *m = LoginResponse{} }
func (m *LoginResponse) String() string { return proto.CompactTextString(m) }
func (*LoginResponse) ProtoMessage() {}
func (*LoginResponse) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{1} }
type LogoutRequest struct {
Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"`
}
func (m *LogoutRequest) Reset() { *m = LogoutRequest{} }
func (m *LogoutRequest) String() string { return proto.CompactTextString(m) }
func (*LogoutRequest) ProtoMessage() {}
func (*LogoutRequest) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{2} }
type LogoutResponse struct {
ErrMsg string `protobuf:"bytes,1,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"`
}
func (m *LogoutResponse) Reset() { *m = LogoutResponse{} }
func (m *LogoutResponse) String() string { return proto.CompactTextString(m) }
func (*LogoutResponse) ProtoMessage() {}
func (*LogoutResponse) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{3} }
func init() {
proto.RegisterType((*LoginRequest)(nil), "session.LoginRequest")
proto.RegisterType((*LoginResponse)(nil), "session.LoginResponse")
proto.RegisterType((*LogoutRequest)(nil), "session.LogoutRequest")
proto.RegisterType((*LogoutResponse)(nil), "session.LogoutResponse")
}
func init() { proto.RegisterFile("services/session/session.proto", fileDescriptorSession) }
var fileDescriptorSession = []byte{
// 231 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x6c, 0x50, 0xcb, 0x4a, 0xc5, 0x30,
0x10, 0x35, 0xc2, 0xed, 0xd5, 0x41, 0xef, 0x62, 0x50, 0x6f, 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xfc, 0x27, 0xf2, 0x43, 0x36, 0x75, 0x7e, 0xf1, 0x11, 0x00, 0x00, 0xff, 0xff, 0xc7,
0x91, 0x50, 0x79, 0x95, 0x01, 0x00, 0x00,
}

View File

@@ -20,6 +20,11 @@ import proto "github.com/gogo/protobuf/proto"
import fmt "fmt"
import math "math"
import (
context "golang.org/x/net/context"
grpc "google.golang.org/grpc"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
@@ -41,6 +46,20 @@ func (m *LoginRequest) String() string { return proto.CompactTextStri
func (*LoginRequest) ProtoMessage() {}
func (*LoginRequest) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{0} }
func (m *LoginRequest) GetUsername() string {
if m != nil {
return m.Username
}
return ""
}
func (m *LoginRequest) GetPassword() string {
if m != nil {
return m.Password
}
return ""
}
type LoginResponse struct {
Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"`
ErrMsg string `protobuf:"bytes,2,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"`
@@ -51,6 +70,20 @@ func (m *LoginResponse) String() string { return proto.CompactTextStr
func (*LoginResponse) ProtoMessage() {}
func (*LoginResponse) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{1} }
func (m *LoginResponse) GetToken() string {
if m != nil {
return m.Token
}
return ""
}
func (m *LoginResponse) GetErrMsg() string {
if m != nil {
return m.ErrMsg
}
return ""
}
type LogoutRequest struct {
Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"`
}
@@ -60,6 +93,13 @@ func (m *LogoutRequest) String() string { return proto.CompactTextStr
func (*LogoutRequest) ProtoMessage() {}
func (*LogoutRequest) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{2} }
func (m *LogoutRequest) GetToken() string {
if m != nil {
return m.Token
}
return ""
}
type LogoutResponse struct {
ErrMsg string `protobuf:"bytes,1,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"`
}
@@ -69,6 +109,13 @@ func (m *LogoutResponse) String() string { return proto.CompactTextSt
func (*LogoutResponse) ProtoMessage() {}
func (*LogoutResponse) Descriptor() ([]byte, []int) { return fileDescriptorSession, []int{3} }
func (m *LogoutResponse) GetErrMsg() string {
if m != nil {
return m.ErrMsg
}
return ""
}
func init() {
proto.RegisterType((*LoginRequest)(nil), "session.LoginRequest")
proto.RegisterType((*LoginResponse)(nil), "session.LoginResponse")
@@ -76,6 +123,111 @@ func init() {
proto.RegisterType((*LogoutResponse)(nil), "session.LogoutResponse")
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion4
// Client API for SessionService service
type SessionServiceClient interface {
Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error)
Logout(ctx context.Context, in *LogoutRequest, opts ...grpc.CallOption) (*LogoutResponse, error)
}
type sessionServiceClient struct {
cc *grpc.ClientConn
}
func NewSessionServiceClient(cc *grpc.ClientConn) SessionServiceClient {
return &sessionServiceClient{cc}
}
func (c *sessionServiceClient) Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) {
out := new(LoginResponse)
err := grpc.Invoke(ctx, "/session.SessionService/Login", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *sessionServiceClient) Logout(ctx context.Context, in *LogoutRequest, opts ...grpc.CallOption) (*LogoutResponse, error) {
out := new(LogoutResponse)
err := grpc.Invoke(ctx, "/session.SessionService/Logout", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for SessionService service
type SessionServiceServer interface {
Login(context.Context, *LoginRequest) (*LoginResponse, error)
Logout(context.Context, *LogoutRequest) (*LogoutResponse, error)
}
func RegisterSessionServiceServer(s *grpc.Server, srv SessionServiceServer) {
s.RegisterService(&_SessionService_serviceDesc, srv)
}
func _SessionService_Login_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(LoginRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SessionServiceServer).Login(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/session.SessionService/Login",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SessionServiceServer).Login(ctx, req.(*LoginRequest))
}
return interceptor(ctx, in, info, handler)
}
func _SessionService_Logout_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(LogoutRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SessionServiceServer).Logout(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/session.SessionService/Logout",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SessionServiceServer).Logout(ctx, req.(*LogoutRequest))
}
return interceptor(ctx, in, info, handler)
}
var _SessionService_serviceDesc = grpc.ServiceDesc{
ServiceName: "session.SessionService",
HandlerType: (*SessionServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Login",
Handler: _SessionService_Login_Handler,
},
{
MethodName: "Logout",
Handler: _SessionService_Logout_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "services/session/session.proto",
}
func init() { proto.RegisterFile("services/session/session.proto", fileDescriptorSession) }
var fileDescriptorSession = []byte{

View File

@@ -0,0 +1,23 @@
package sessionsvc
import (
"fmt"
"golang.org/x/net/context"
pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session"
)
type Service struct{}
func New() pb.SessionServiceServer {
return &Service{}
}
func (svc *Service) Login(ctx context.Context, in *pb.LoginRequest) (*pb.LoginResponse, error) {
return nil, fmt.Errorf("not implemented")
}
func (svc *Service) Logout(ctx context.Context, in *pb.LogoutRequest) (*pb.LogoutResponse, error) {
return nil, fmt.Errorf("not implemented")
}