Go test project (1st learning step)

This commit is contained in:
Dirk Jahnke 2019-10-15 19:42:24 +02:00
parent ee5b5509aa
commit 8bf63c7ab0
6 changed files with 500 additions and 0 deletions

3
Makefile Normal file
View File

@ -0,0 +1,3 @@
build:
protoc -I. --go_out=plugins=grpc:. \
proto/consignment/consignment.proto

12
go.mod Normal file
View File

@ -0,0 +1,12 @@
module gitea.pmpark.de/dirk/shippy-service-consignment
go 1.13
require (
github.com/golang/protobuf v1.3.2
golang.org/x/net v0.0.0-20191014212845-da9a3fd4c582 // indirect
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 // indirect
golang.org/x/text v0.3.2 // indirect
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03 // indirect
google.golang.org/grpc v1.24.0
)

50
go.sum Normal file
View File

@ -0,0 +1,50 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
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=
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/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20191014212845-da9a3fd4c582 h1:p9xBe/w/OzkeYVKm234g55gMdD1nSIooTir5kV11kfA=
golang.org/x/net v0.0.0-20191014212845-da9a3fd4c582/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03 h1:4HYDjxeNXAOTv3o1N2tjo8UUSlhQgAD52FVkwxnWgM8=
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.24.0 h1:vb/1TCsVn3DcJlQ0Gs1yB1pKI6Do2/QNwxdKqmc/b0s=
google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

88
main.go Normal file
View File

@ -0,0 +1,88 @@
// shippy-service-consignment/main.go
package main
import (
"context"
"log"
"net"
"sync"
// Import the generated protobuf code
//pb "github.com/<YourUserName>/shippy-service-consignment/proto/consignment"
pb "gitea.pmpark.de/dirk/shippy-service-consignment/proto/consignment"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
const (
port = ":50051"
)
type repository interface {
Create(*pb.Consignment) (*pb.Consignment, error)
}
// Repository - Dummy repository, this simulates the use of a datastore
// of some kind. We'll replace this with a real implementation later on.
type Repository struct {
mu sync.RWMutex
consignments []*pb.Consignment
}
// Create a new consignment
func (repo *Repository) Create(consignment *pb.Consignment) (*pb.Consignment, error) {
repo.mu.Lock()
updated := append(repo.consignments, consignment)
repo.consignments = updated
repo.mu.Unlock()
return consignment, nil
}
// Service should implement all of the methods to satisfy the service
// we defined in our protobuf definition. You can check the interface
// in the generated code itself for the exact method signatures etc
// to give you a better idea.
type service struct {
repo repository
}
// CreateConsignment - we created just one method on our service,
// which is a create method, which takes a context and a request as an
// argument, these are handled by the gRPC server.
func (s *service) CreateConsignment(ctx context.Context, req *pb.Consignment) (*pb.Response, error) {
// Save our consignment
consignment, err := s.repo.Create(req)
if err != nil {
return nil, err
}
// Return matching the `Response` message we created in our
// protobuf definition.
return &pb.Response{Created: true, Consignment: consignment}, nil
}
func main() {
repo := &Repository{}
// Set-up our gRPC server.
lis, err := net.Listen("tcp", port)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer()
// Register our service with the gRPC server, this will tie our
// implementation into the auto-generated interface code for our
// protobuf definition.
pb.RegisterShippingServiceServer(s, &service{repo})
// Register reflection service on gRPC server.
reflection.Register(s)
log.Println("Running on port:", port)
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}

View File

@ -0,0 +1,319 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: proto/consignment/consignment.proto
package consignment
import (
context "context"
fmt "fmt"
proto "github.com/golang/protobuf/proto"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
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.ProtoPackageIsVersion3 // please upgrade the proto package
type Consignment struct {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"`
Weight int32 `protobuf:"varint,3,opt,name=weight,proto3" json:"weight,omitempty"`
Containers []*Container `protobuf:"bytes,4,rep,name=containers,proto3" json:"containers,omitempty"`
VesselId string `protobuf:"bytes,5,opt,name=vessel_id,json=vesselId,proto3" json:"vessel_id,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Consignment) Reset() { *m = Consignment{} }
func (m *Consignment) String() string { return proto.CompactTextString(m) }
func (*Consignment) ProtoMessage() {}
func (*Consignment) Descriptor() ([]byte, []int) {
return fileDescriptor_e5e5ab05dfa973d5, []int{0}
}
func (m *Consignment) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Consignment.Unmarshal(m, b)
}
func (m *Consignment) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Consignment.Marshal(b, m, deterministic)
}
func (m *Consignment) XXX_Merge(src proto.Message) {
xxx_messageInfo_Consignment.Merge(m, src)
}
func (m *Consignment) XXX_Size() int {
return xxx_messageInfo_Consignment.Size(m)
}
func (m *Consignment) XXX_DiscardUnknown() {
xxx_messageInfo_Consignment.DiscardUnknown(m)
}
var xxx_messageInfo_Consignment proto.InternalMessageInfo
func (m *Consignment) GetId() string {
if m != nil {
return m.Id
}
return ""
}
func (m *Consignment) GetDescription() string {
if m != nil {
return m.Description
}
return ""
}
func (m *Consignment) GetWeight() int32 {
if m != nil {
return m.Weight
}
return 0
}
func (m *Consignment) GetContainers() []*Container {
if m != nil {
return m.Containers
}
return nil
}
func (m *Consignment) GetVesselId() string {
if m != nil {
return m.VesselId
}
return ""
}
type Container struct {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
CustomerId string `protobuf:"bytes,2,opt,name=customer_id,json=customerId,proto3" json:"customer_id,omitempty"`
Origin string `protobuf:"bytes,3,opt,name=origin,proto3" json:"origin,omitempty"`
UserId string `protobuf:"bytes,4,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Container) Reset() { *m = Container{} }
func (m *Container) String() string { return proto.CompactTextString(m) }
func (*Container) ProtoMessage() {}
func (*Container) Descriptor() ([]byte, []int) {
return fileDescriptor_e5e5ab05dfa973d5, []int{1}
}
func (m *Container) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Container.Unmarshal(m, b)
}
func (m *Container) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Container.Marshal(b, m, deterministic)
}
func (m *Container) XXX_Merge(src proto.Message) {
xxx_messageInfo_Container.Merge(m, src)
}
func (m *Container) XXX_Size() int {
return xxx_messageInfo_Container.Size(m)
}
func (m *Container) XXX_DiscardUnknown() {
xxx_messageInfo_Container.DiscardUnknown(m)
}
var xxx_messageInfo_Container proto.InternalMessageInfo
func (m *Container) GetId() string {
if m != nil {
return m.Id
}
return ""
}
func (m *Container) GetCustomerId() string {
if m != nil {
return m.CustomerId
}
return ""
}
func (m *Container) GetOrigin() string {
if m != nil {
return m.Origin
}
return ""
}
func (m *Container) GetUserId() string {
if m != nil {
return m.UserId
}
return ""
}
type Response struct {
Created bool `protobuf:"varint,1,opt,name=created,proto3" json:"created,omitempty"`
Consignment *Consignment `protobuf:"bytes,2,opt,name=consignment,proto3" json:"consignment,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Response) Reset() { *m = Response{} }
func (m *Response) String() string { return proto.CompactTextString(m) }
func (*Response) ProtoMessage() {}
func (*Response) Descriptor() ([]byte, []int) {
return fileDescriptor_e5e5ab05dfa973d5, []int{2}
}
func (m *Response) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Response.Unmarshal(m, b)
}
func (m *Response) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Response.Marshal(b, m, deterministic)
}
func (m *Response) XXX_Merge(src proto.Message) {
xxx_messageInfo_Response.Merge(m, src)
}
func (m *Response) XXX_Size() int {
return xxx_messageInfo_Response.Size(m)
}
func (m *Response) XXX_DiscardUnknown() {
xxx_messageInfo_Response.DiscardUnknown(m)
}
var xxx_messageInfo_Response proto.InternalMessageInfo
func (m *Response) GetCreated() bool {
if m != nil {
return m.Created
}
return false
}
func (m *Response) GetConsignment() *Consignment {
if m != nil {
return m.Consignment
}
return nil
}
func init() {
proto.RegisterType((*Consignment)(nil), "consignment.Consignment")
proto.RegisterType((*Container)(nil), "consignment.Container")
proto.RegisterType((*Response)(nil), "consignment.Response")
}
func init() {
proto.RegisterFile("proto/consignment/consignment.proto", fileDescriptor_e5e5ab05dfa973d5)
}
var fileDescriptor_e5e5ab05dfa973d5 = []byte{
// 296 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x51, 0x4f, 0x4b, 0x3b, 0x31,
0x10, 0xfd, 0x6d, 0xff, 0xef, 0x04, 0x7e, 0x62, 0xc0, 0x1a, 0xf4, 0xe0, 0xb2, 0x5e, 0x7a, 0xaa,
0x50, 0xc1, 0x83, 0xd7, 0x82, 0xd0, 0x6b, 0x7a, 0xf2, 0xa4, 0x35, 0x19, 0xb6, 0x03, 0x36, 0x59,
0x92, 0xb4, 0x7e, 0x29, 0x3f, 0xa4, 0x6c, 0xb6, 0xab, 0x51, 0xf1, 0x36, 0xef, 0xbd, 0x99, 0x79,
0x2f, 0x19, 0xb8, 0xae, 0x9d, 0x0d, 0xf6, 0x46, 0x59, 0xe3, 0xa9, 0x32, 0x3b, 0x34, 0x21, 0xad,
0xe7, 0x51, 0xe5, 0x2c, 0xa1, 0xca, 0xf7, 0x0c, 0xd8, 0xf2, 0x0b, 0xf3, 0xff, 0xd0, 0x23, 0x2d,
0xb2, 0x22, 0x9b, 0xe5, 0xb2, 0x47, 0x9a, 0x17, 0xc0, 0x34, 0x7a, 0xe5, 0xa8, 0x0e, 0x64, 0x8d,
0xe8, 0x45, 0x21, 0xa5, 0xf8, 0x14, 0x46, 0x6f, 0x48, 0xd5, 0x36, 0x88, 0x7e, 0x91, 0xcd, 0x86,
0xf2, 0x88, 0xf8, 0x1d, 0x80, 0xb2, 0x26, 0x6c, 0xc8, 0xa0, 0xf3, 0x62, 0x50, 0xf4, 0x67, 0x6c,
0x31, 0x9d, 0xa7, 0x71, 0x96, 0x9d, 0x2c, 0x93, 0x4e, 0x7e, 0x09, 0xf9, 0x01, 0xbd, 0xc7, 0xd7,
0x27, 0xd2, 0x62, 0x18, 0xfd, 0x26, 0x2d, 0xb1, 0xd2, 0xe5, 0x0e, 0xf2, 0xcf, 0xa9, 0x5f, 0x59,
0xaf, 0x80, 0xa9, 0xbd, 0x0f, 0x76, 0x87, 0xae, 0x99, 0x6d, 0xb3, 0x42, 0x47, 0xad, 0x74, 0x13,
0xd5, 0x3a, 0xaa, 0xc8, 0xc4, 0xa8, 0xb9, 0x3c, 0x22, 0x7e, 0x0e, 0xe3, 0xbd, 0x6f, 0x87, 0x06,
0xad, 0xd0, 0xc0, 0x95, 0x2e, 0x9f, 0x61, 0x22, 0xd1, 0xd7, 0xd6, 0x78, 0xe4, 0x02, 0xc6, 0xca,
0xe1, 0x26, 0x60, 0x6b, 0x39, 0x91, 0x1d, 0xe4, 0xf7, 0x90, 0x7e, 0x69, 0xf4, 0x65, 0x0b, 0xf1,
0xf3, 0xa9, 0x5d, 0x2d, 0xd3, 0xe6, 0xc5, 0x23, 0x9c, 0xac, 0xb7, 0x54, 0xd7, 0x64, 0xaa, 0x35,
0xba, 0x03, 0x29, 0xe4, 0x0f, 0x70, 0xba, 0x8c, 0x9b, 0xd3, 0xbb, 0xfc, 0xb9, 0xee, 0xe2, 0xec,
0x9b, 0xd2, 0xc5, 0x2d, 0xff, 0xbd, 0x8c, 0xe2, 0xb9, 0x6f, 0x3f, 0x02, 0x00, 0x00, 0xff, 0xff,
0x5d, 0xef, 0xe4, 0xb7, 0x15, 0x02, 0x00, 0x00,
}
// 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
// ShippingServiceClient is the client API for ShippingService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type ShippingServiceClient interface {
CreateConsignment(ctx context.Context, in *Consignment, opts ...grpc.CallOption) (*Response, error)
}
type shippingServiceClient struct {
cc *grpc.ClientConn
}
func NewShippingServiceClient(cc *grpc.ClientConn) ShippingServiceClient {
return &shippingServiceClient{cc}
}
func (c *shippingServiceClient) CreateConsignment(ctx context.Context, in *Consignment, opts ...grpc.CallOption) (*Response, error) {
out := new(Response)
err := c.cc.Invoke(ctx, "/consignment.ShippingService/CreateConsignment", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// ShippingServiceServer is the server API for ShippingService service.
type ShippingServiceServer interface {
CreateConsignment(context.Context, *Consignment) (*Response, error)
}
// UnimplementedShippingServiceServer can be embedded to have forward compatible implementations.
type UnimplementedShippingServiceServer struct {
}
func (*UnimplementedShippingServiceServer) CreateConsignment(ctx context.Context, req *Consignment) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method CreateConsignment not implemented")
}
func RegisterShippingServiceServer(s *grpc.Server, srv ShippingServiceServer) {
s.RegisterService(&_ShippingService_serviceDesc, srv)
}
func _ShippingService_CreateConsignment_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Consignment)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ShippingServiceServer).CreateConsignment(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/consignment.ShippingService/CreateConsignment",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ShippingServiceServer).CreateConsignment(ctx, req.(*Consignment))
}
return interceptor(ctx, in, info, handler)
}
var _ShippingService_serviceDesc = grpc.ServiceDesc{
ServiceName: "consignment.ShippingService",
HandlerType: (*ShippingServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "CreateConsignment",
Handler: _ShippingService_CreateConsignment_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "proto/consignment/consignment.proto",
}

View File

@ -0,0 +1,28 @@
// shippy-service-consignment/proto/consignment/consignment.proto
syntax = "proto3";
package consignment;
service ShippingService {
rpc CreateConsignment(Consignment) returns (Response) {}
}
message Consignment {
string id = 1;
string description = 2;
int32 weight = 3;
repeated Container containers = 4;
string vessel_id = 5;
}
message Container {
string id = 1;
string customer_id = 2;
string origin = 3;
string user_id = 4;
}
message Response {
bool created = 1;
Consignment consignment = 2;
}