got protobuf + go working together.

This commit is contained in:
Patrick Balestra
2020-02-04 15:37:34 +01:00
parent ca3213b9f6
commit 2346ef47a3
6 changed files with 166 additions and 29 deletions
+142 -14
View File
@@ -7,7 +7,10 @@ import (
context "context"
fmt "fmt"
proto "github.com/golang/protobuf/proto"
v1 "github.com/spotify/backstage/backend/proto/identity/v1"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
math "math"
)
@@ -22,9 +25,80 @@ var _ = math.Inf
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type Empty struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Empty) Reset() { *m = Empty{} }
func (m *Empty) String() string { return proto.CompactTextString(m) }
func (*Empty) ProtoMessage() {}
func (*Empty) Descriptor() ([]byte, []int) {
return fileDescriptor_6737326b433dc57d, []int{0}
}
func (m *Empty) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Empty.Unmarshal(m, b)
}
func (m *Empty) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Empty.Marshal(b, m, deterministic)
}
func (m *Empty) XXX_Merge(src proto.Message) {
xxx_messageInfo_Empty.Merge(m, src)
}
func (m *Empty) XXX_Size() int {
return xxx_messageInfo_Empty.Size(m)
}
func (m *Empty) XXX_DiscardUnknown() {
xxx_messageInfo_Empty.DiscardUnknown(m)
}
var xxx_messageInfo_Empty proto.InternalMessageInfo
type GetAllTemplatesResponse struct {
Templates []*Template `protobuf:"bytes,1,rep,name=templates,proto3" json:"templates,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *GetAllTemplatesResponse) Reset() { *m = GetAllTemplatesResponse{} }
func (m *GetAllTemplatesResponse) String() string { return proto.CompactTextString(m) }
func (*GetAllTemplatesResponse) ProtoMessage() {}
func (*GetAllTemplatesResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_6737326b433dc57d, []int{1}
}
func (m *GetAllTemplatesResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_GetAllTemplatesResponse.Unmarshal(m, b)
}
func (m *GetAllTemplatesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_GetAllTemplatesResponse.Marshal(b, m, deterministic)
}
func (m *GetAllTemplatesResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_GetAllTemplatesResponse.Merge(m, src)
}
func (m *GetAllTemplatesResponse) XXX_Size() int {
return xxx_messageInfo_GetAllTemplatesResponse.Size(m)
}
func (m *GetAllTemplatesResponse) XXX_DiscardUnknown() {
xxx_messageInfo_GetAllTemplatesResponse.DiscardUnknown(m)
}
var xxx_messageInfo_GetAllTemplatesResponse proto.InternalMessageInfo
func (m *GetAllTemplatesResponse) GetTemplates() []*Template {
if m != nil {
return m.Templates
}
return nil
}
type Template struct {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
User *v1.User `protobuf:"bytes,3,opt,name=user,proto3" json:"user,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@@ -34,7 +108,7 @@ func (m *Template) Reset() { *m = Template{} }
func (m *Template) String() string { return proto.CompactTextString(m) }
func (*Template) ProtoMessage() {}
func (*Template) Descriptor() ([]byte, []int) {
return fileDescriptor_6737326b433dc57d, []int{0}
return fileDescriptor_6737326b433dc57d, []int{2}
}
func (m *Template) XXX_Unmarshal(b []byte) error {
@@ -69,23 +143,39 @@ func (m *Template) GetName() string {
return ""
}
func (m *Template) GetUser() *v1.User {
if m != nil {
return m.User
}
return nil
}
func init() {
proto.RegisterType((*Empty)(nil), "spotify.backstage.scaffolder.v1.Empty")
proto.RegisterType((*GetAllTemplatesResponse)(nil), "spotify.backstage.scaffolder.v1.GetAllTemplatesResponse")
proto.RegisterType((*Template)(nil), "spotify.backstage.scaffolder.v1.Template")
}
func init() { proto.RegisterFile("scaffolder/v1/scaffolder.proto", fileDescriptor_6737326b433dc57d) }
var fileDescriptor_6737326b433dc57d = []byte{
// 134 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2b, 0x4e, 0x4e, 0x4c,
0x4b, 0xcb, 0xcf, 0x49, 0x49, 0x2d, 0xd2, 0x2f, 0x33, 0xd4, 0x47, 0xf0, 0xf4, 0x0a, 0x8a, 0xf2,
0x4b, 0xf2, 0x85, 0xe4, 0x8b, 0x0b, 0xf2, 0x4b, 0x32, 0xd3, 0x2a, 0xf5, 0x92, 0x12, 0x93, 0xb3,
0x8b, 0x4b, 0x12, 0xd3, 0x53, 0xf5, 0x90, 0xd4, 0x94, 0x19, 0x2a, 0xe9, 0x71, 0x71, 0x84, 0xa4,
0xe6, 0x16, 0xe4, 0x24, 0x96, 0xa4, 0x0a, 0xf1, 0x71, 0x31, 0x65, 0xa6, 0x48, 0x30, 0x2a, 0x30,
0x6a, 0x70, 0x06, 0x31, 0x65, 0xa6, 0x08, 0x09, 0x71, 0xb1, 0xe4, 0x25, 0xe6, 0xa6, 0x4a, 0x30,
0x81, 0x45, 0xc0, 0x6c, 0x23, 0x1e, 0x2e, 0xae, 0x60, 0xb8, 0x01, 0x4e, 0x7c, 0x51, 0x3c, 0x08,
0xe3, 0xca, 0x0c, 0x93, 0xd8, 0xc0, 0xb6, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x6b, 0x4e,
0xc5, 0xeb, 0x97, 0x00, 0x00, 0x00,
// 254 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x90, 0x4f, 0x4b, 0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74, 0x89, 0x78, 0xb1, 0xd8, 0x66, 0x0e, 0x48, 0x3f, 0x18,
0xc0, 0xd3, 0xfe, 0x1c, 0x6e, 0xe1, 0xf4, 0x57, 0x36, 0x7e, 0x35, 0x19, 0xc0, 0xd5, 0x12, 0xdc,
0x4d, 0xfa, 0xfe, 0x69, 0xed, 0x61, 0xf5, 0x7a, 0x32, 0x1a, 0xbb, 0x24, 0x3f, 0x74, 0x85, 0xdf,
0x7c, 0x06, 0x00, 0x00, 0xff, 0xff, 0x6c, 0x28, 0xe6, 0x58, 0xcf, 0x01, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
@@ -100,6 +190,7 @@ const _ = grpc.SupportPackageIsVersion6
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type ScaffolderClient interface {
GetAllTemplates(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*GetAllTemplatesResponse, error)
}
type scaffolderClient struct {
@@ -110,22 +201,59 @@ func NewScaffolderClient(cc grpc.ClientConnInterface) ScaffolderClient {
return &scaffolderClient{cc}
}
func (c *scaffolderClient) GetAllTemplates(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*GetAllTemplatesResponse, error) {
out := new(GetAllTemplatesResponse)
err := c.cc.Invoke(ctx, "/spotify.backstage.scaffolder.v1.Scaffolder/GetAllTemplates", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// ScaffolderServer is the server API for Scaffolder service.
type ScaffolderServer interface {
GetAllTemplates(context.Context, *Empty) (*GetAllTemplatesResponse, error)
}
// UnimplementedScaffolderServer can be embedded to have forward compatible implementations.
type UnimplementedScaffolderServer struct {
}
func (*UnimplementedScaffolderServer) GetAllTemplates(ctx context.Context, req *Empty) (*GetAllTemplatesResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetAllTemplates not implemented")
}
func RegisterScaffolderServer(s *grpc.Server, srv ScaffolderServer) {
s.RegisterService(&_Scaffolder_serviceDesc, srv)
}
func _Scaffolder_GetAllTemplates_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Empty)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ScaffolderServer).GetAllTemplates(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/spotify.backstage.scaffolder.v1.Scaffolder/GetAllTemplates",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ScaffolderServer).GetAllTemplates(ctx, req.(*Empty))
}
return interceptor(ctx, in, info, handler)
}
var _Scaffolder_serviceDesc = grpc.ServiceDesc{
ServiceName: "spotify.backstage.scaffolder.v1.Scaffolder",
HandlerType: (*ScaffolderServer)(nil),
Methods: []grpc.MethodDesc{},
Streams: []grpc.StreamDesc{},
Metadata: "scaffolder/v1/scaffolder.proto",
Methods: []grpc.MethodDesc{
{
MethodName: "GetAllTemplates",
Handler: _Scaffolder_GetAllTemplates_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "scaffolder/v1/scaffolder.proto",
}
+3 -3
View File
@@ -1,10 +1,10 @@
module github.com/spotify/backstage/identity
module github.com/spotify/backstage/scaffolder
go 1.13
replace github.com/spotify/backstage/proto => ../proto
replace github.com/spotify/backstage/backend/proto => ../proto
require (
github.com/spotify/backstage/proto v0.0.0-00010101000000-000000000000
github.com/spotify/backstage/backend/proto v0.0.0-00010101000000-000000000000 // indirect
google.golang.org/grpc v1.27.0
)
+2
View File
@@ -4,6 +4,7 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@@ -11,6 +12,7 @@ github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+6 -10
View File
@@ -5,7 +5,7 @@ import (
"log"
"net"
identityv1 "github.com/spotify/backstage/proto/identity/v1"
pb "github.com/spotify/backstage/backend/proto/scaffolder/v1"
"google.golang.org/grpc"
)
@@ -20,19 +20,15 @@ func main() {
}
grpcServer := grpc.NewServer()
identityv1.RegisterIdentityServer(grpcServer, &server{})
pb.RegisterScaffolderServer(grpcServer, &server{})
log.Println("Serving Identity Service")
log.Println("Serving Scaffolder Service")
grpcServer.Serve(lis)
}
type server struct {
}
func (s *server) GetUser(ctx context.Context, req *identityv1.GetUserRequest) (*identityv1.GetUserReply, error) {
return &identityv1.GetUserReply{}, nil
}
func (s *server) GetGroup(ctx context.Context, req *identityv1.GetGroupRequest) (*identityv1.GetGroupReply, error) {
return &identityv1.GetGroupReply{}, nil
}
func (s *server) GetAllTemplates(ctx context.Context, req *pb.Empty) (*pb.GetAllTemplatesResponse, error) {
return &pb.GetAllTemplatesResponse{}, nil
}
+1 -1
View File
@@ -10,7 +10,7 @@ lint:
path: ../LICENSE
generate:
go_options:
import_path: github.com/spotify/backstage
import_path: github.com/spotify/backstage/backend
plugins:
- name: go
type: go
+12 -1
View File
@@ -2,11 +2,22 @@ syntax = "proto3";
package spotify.backstage.scaffolder.v1;
import "identity/v1/identity.proto";
option go_package = "scaffolderv1";
service Scaffolder {}
service Scaffolder {
rpc GetAllTemplates(Empty) returns (GetAllTemplatesResponse);
}
message Empty {}
message GetAllTemplatesResponse {
repeated Template templates = 1;
}
message Template {
string id = 1;
string name = 2;
spotify.backstage.identity.v1.User user = 3;
}