Skip to content

Commit

Permalink
Merge pull request #55 from izumin5210/izumin5210/register-funcs
Browse files Browse the repository at this point in the history
 Split register funcs from genrated foo_server.go
  • Loading branch information
izumin5210 authored Apr 13, 2018
2 parents 37ab2a3 + 447abde commit 4201514
Show file tree
Hide file tree
Showing 26 changed files with 253 additions and 153 deletions.
12 changes: 0 additions & 12 deletions _tests/integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,24 +224,12 @@ func updateServerImpl(t *testing.T, fs afero.Fs, rootPath string) {
Value: strconv.Quote("context"),
},
},
&ast.ImportSpec{
Path: &ast.BasicLit{
Kind: token.STRING,
Value: strconv.Quote("github.com/grpc-ecosystem/grpc-gateway/runtime"),
},
},
&ast.ImportSpec{
Path: &ast.BasicLit{
Kind: token.STRING,
Value: strconv.Quote("github.com/izumin5210/grapi/pkg/grapiserver"),
},
},
&ast.ImportSpec{
Path: &ast.BasicLit{
Kind: token.STRING,
Value: strconv.Quote("google.golang.org/grpc"),
},
},
&ast.ImportSpec{
Name: &ast.Ident{Name: "api_pb"},
Path: &ast.BasicLit{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package server
import (
"context"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/izumin5210/grapi/pkg/grapiserver"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand All @@ -23,13 +21,3 @@ func NewBookServiceServer() interface {
type bookServiceServerImpl struct {
}

// RegisterWithServer implements grapiserver.Server.RegisterWithServer.
func (s *bookServiceServerImpl) RegisterWithServer(grpcSvr *grpc.Server) {
api_pb.RegisterBookServiceServer(grpcSvr, s)
}

// RegisterWithHandler implements grapiserver.Server.RegisterWithHandler.
func (s *bookServiceServerImpl) RegisterWithHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return api_pb.RegisterBookServiceHandler(ctx, mux, conn)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package server

import (
"context"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"

api_pb "testapp/api"
)

// RegisterWithServer implements grapiserver.Server.RegisterWithServer.
func (s *bookServiceServerImpl) RegisterWithServer(grpcSvr *grpc.Server) {
api_pb.RegisterBookServiceServer(grpcSvr, s)
}

// RegisterWithHandler implements grapiserver.Server.RegisterWithHandler.
func (s *bookServiceServerImpl) RegisterWithHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return api_pb.RegisterBookServiceHandler(ctx, mux, conn)
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import (
"context"

"github.com/golang/protobuf/ptypes/empty"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/izumin5210/grapi/pkg/grapiserver"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand All @@ -24,16 +22,6 @@ func NewBookServiceServer() interface {
type bookServiceServerImpl struct {
}

// RegisterWithServer implements grapiserver.Server.RegisterWithServer.
func (s *bookServiceServerImpl) RegisterWithServer(grpcSvr *grpc.Server) {
api_pb.RegisterBookServiceServer(grpcSvr, s)
}

// RegisterWithHandler implements grapiserver.Server.RegisterWithHandler.
func (s *bookServiceServerImpl) RegisterWithHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return api_pb.RegisterBookServiceHandler(ctx, mux, conn)
}

func (s *bookServiceServerImpl) ListBooks(ctx context.Context, req *api_pb.ListBooksRequest) (*api_pb.ListBooksResponse, error) {
// TODO: Not yet implemented.
return nil, status.Error(codes.Unimplemented, "TODO: You should implement it!")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package server

import (
"context"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"

api_pb "testapp/api"
)

// RegisterWithServer implements grapiserver.Server.RegisterWithServer.
func (s *bookServiceServerImpl) RegisterWithServer(grpcSvr *grpc.Server) {
api_pb.RegisterBookServiceServer(grpcSvr, s)
}

// RegisterWithHandler implements grapiserver.Server.RegisterWithHandler.
func (s *bookServiceServerImpl) RegisterWithHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return api_pb.RegisterBookServiceHandler(ctx, mux, conn)
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package server
import (
"context"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/izumin5210/grapi/pkg/grapiserver"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand All @@ -23,13 +21,3 @@ func NewFooServiceServer() interface {
type fooServiceServerImpl struct {
}

// RegisterWithServer implements grapiserver.Server.RegisterWithServer.
func (s *fooServiceServerImpl) RegisterWithServer(grpcSvr *grpc.Server) {
api_pb.RegisterFooServiceServer(grpcSvr, s)
}

// RegisterWithHandler implements grapiserver.Server.RegisterWithHandler.
func (s *fooServiceServerImpl) RegisterWithHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return api_pb.RegisterFooServiceHandler(ctx, mux, conn)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package server

import (
"context"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"

api_pb "testapp/api"
)

// RegisterWithServer implements grapiserver.Server.RegisterWithServer.
func (s *fooServiceServerImpl) RegisterWithServer(grpcSvr *grpc.Server) {
api_pb.RegisterFooServiceServer(grpcSvr, s)
}

// RegisterWithHandler implements grapiserver.Server.RegisterWithHandler.
func (s *fooServiceServerImpl) RegisterWithHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return api_pb.RegisterFooServiceHandler(ctx, mux, conn)
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package foo
import (
"context"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/izumin5210/grapi/pkg/grapiserver"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand All @@ -23,13 +21,3 @@ func NewBarServiceServer() interface {
type barServiceServerImpl struct {
}

// RegisterWithServer implements grapiserver.Server.RegisterWithServer.
func (s *barServiceServerImpl) RegisterWithServer(grpcSvr *grpc.Server) {
foo_pb.RegisterBarServiceServer(grpcSvr, s)
}

// RegisterWithHandler implements grapiserver.Server.RegisterWithHandler.
func (s *barServiceServerImpl) RegisterWithHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return foo_pb.RegisterBarServiceHandler(ctx, mux, conn)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package foo

import (
"context"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"

foo_pb "testapp/api/foo"
)

// RegisterWithServer implements grapiserver.Server.RegisterWithServer.
func (s *barServiceServerImpl) RegisterWithServer(grpcSvr *grpc.Server) {
foo_pb.RegisterBarServiceServer(grpcSvr, s)
}

// RegisterWithHandler implements grapiserver.Server.RegisterWithHandler.
func (s *barServiceServerImpl) RegisterWithHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return foo_pb.RegisterBarServiceHandler(ctx, mux, conn)
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package foo
import (
"context"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/izumin5210/grapi/pkg/grapiserver"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand All @@ -23,13 +21,3 @@ func NewBarBazServiceServer() interface {
type barBazServiceServerImpl struct {
}

// RegisterWithServer implements grapiserver.Server.RegisterWithServer.
func (s *barBazServiceServerImpl) RegisterWithServer(grpcSvr *grpc.Server) {
foo_pb.RegisterBarBazServiceServer(grpcSvr, s)
}

// RegisterWithHandler implements grapiserver.Server.RegisterWithHandler.
func (s *barBazServiceServerImpl) RegisterWithHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return foo_pb.RegisterBarBazServiceHandler(ctx, mux, conn)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package foo

import (
"context"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"

foo_pb "testapp/api/foo"
)

// RegisterWithServer implements grapiserver.Server.RegisterWithServer.
func (s *barBazServiceServerImpl) RegisterWithServer(grpcSvr *grpc.Server) {
foo_pb.RegisterBarBazServiceServer(grpcSvr, s)
}

// RegisterWithHandler implements grapiserver.Server.RegisterWithHandler.
func (s *barBazServiceServerImpl) RegisterWithHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return foo_pb.RegisterBarBazServiceHandler(ctx, mux, conn)
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import (
"context"

"github.com/golang/protobuf/ptypes/empty"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/izumin5210/grapi/pkg/grapiserver"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand All @@ -24,16 +22,6 @@ func NewBarBazServiceServer() interface {
type barBazServiceServerImpl struct {
}

// RegisterWithServer implements grapiserver.Server.RegisterWithServer.
func (s *barBazServiceServerImpl) RegisterWithServer(grpcSvr *grpc.Server) {
foo_pb.RegisterBarBazServiceServer(grpcSvr, s)
}

// RegisterWithHandler implements grapiserver.Server.RegisterWithHandler.
func (s *barBazServiceServerImpl) RegisterWithHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return foo_pb.RegisterBarBazServiceHandler(ctx, mux, conn)
}

func (s *barBazServiceServerImpl) ListBarBazs(ctx context.Context, req *foo_pb.ListBarBazsRequest) (*foo_pb.ListBarBazsResponse, error) {
// TODO: Not yet implemented.
return nil, status.Error(codes.Unimplemented, "TODO: You should implement it!")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package foo

import (
"context"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"

foo_pb "testapp/api/foo"
)

// RegisterWithServer implements grapiserver.Server.RegisterWithServer.
func (s *barBazServiceServerImpl) RegisterWithServer(grpcSvr *grpc.Server) {
foo_pb.RegisterBarBazServiceServer(grpcSvr, s)
}

// RegisterWithHandler implements grapiserver.Server.RegisterWithHandler.
func (s *barBazServiceServerImpl) RegisterWithHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return foo_pb.RegisterBarBazServiceHandler(ctx, mux, conn)
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import (
"context"

"github.com/golang/protobuf/ptypes/empty"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/izumin5210/grapi/pkg/grapiserver"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand All @@ -24,16 +22,6 @@ func NewBarBazServiceServer() interface {
type barBazServiceServerImpl struct {
}

// RegisterWithServer implements grapiserver.Server.RegisterWithServer.
func (s *barBazServiceServerImpl) RegisterWithServer(grpcSvr *grpc.Server) {
foo_pb.RegisterBarBazServiceServer(grpcSvr, s)
}

// RegisterWithHandler implements grapiserver.Server.RegisterWithHandler.
func (s *barBazServiceServerImpl) RegisterWithHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return foo_pb.RegisterBarBazServiceHandler(ctx, mux, conn)
}

func (s *barBazServiceServerImpl) ListBarBazs(ctx context.Context, req *foo_pb.ListBarBazsRequest) (*foo_pb.ListBarBazsResponse, error) {
// TODO: Not yet implemented.
return nil, status.Error(codes.Unimplemented, "TODO: You should implement it!")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package foo

import (
"context"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"

foo_pb "testapp/api/foo"
)

// RegisterWithServer implements grapiserver.Server.RegisterWithServer.
func (s *barBazServiceServerImpl) RegisterWithServer(grpcSvr *grpc.Server) {
foo_pb.RegisterBarBazServiceServer(grpcSvr, s)
}

// RegisterWithHandler implements grapiserver.Server.RegisterWithHandler.
func (s *barBazServiceServerImpl) RegisterWithHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return foo_pb.RegisterBarBazServiceHandler(ctx, mux, conn)
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package foo
import (
"context"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/izumin5210/grapi/pkg/grapiserver"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand All @@ -23,13 +21,3 @@ func NewBarBazServiceServer() interface {
type barBazServiceServerImpl struct {
}

// RegisterWithServer implements grapiserver.Server.RegisterWithServer.
func (s *barBazServiceServerImpl) RegisterWithServer(grpcSvr *grpc.Server) {
foo_pb.RegisterBarBazServiceServer(grpcSvr, s)
}

// RegisterWithHandler implements grapiserver.Server.RegisterWithHandler.
func (s *barBazServiceServerImpl) RegisterWithHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return foo_pb.RegisterBarBazServiceHandler(ctx, mux, conn)
}

Loading

0 comments on commit 4201514

Please sign in to comment.