From 9dece8debaf4e50b2838a6b0a56b793680eacb1d Mon Sep 17 00:00:00 2001 From: aespinro Date: Mon, 19 Aug 2024 02:23:44 +0200 Subject: [PATCH] wip --- cmd/main.go | 15 ++ go.mod | 22 ++ go.sum | 43 ++++ internal/app/app.go | 126 +++++++++++ internal/logging/logging.go | 52 +++++ internal/server/server.go | 24 +++ internal/service/service.go | 342 +++++++++++++++++++++++++++++ pkg/api/api.pb.go | 418 ++++++++++++++++++++++++++++++++++++ pkg/api/api.proto | 33 +++ pkg/api/api_grpc.pb.go | 109 ++++++++++ pkg/api/generate.go | 3 + 11 files changed, 1187 insertions(+) create mode 100644 cmd/main.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/app/app.go create mode 100644 internal/logging/logging.go create mode 100644 internal/server/server.go create mode 100644 internal/service/service.go create mode 100644 pkg/api/api.pb.go create mode 100644 pkg/api/api.proto create mode 100644 pkg/api/api_grpc.pb.go create mode 100644 pkg/api/generate.go diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 0000000..51699eb --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + "log" + + "git.espin.casa/albert/cml04-printer-robot/internal/app" +) + +func main() { + if err := app.Run(); err != nil { + err := fmt.Errorf("failed to start cml04-printer-robot due: %s", err.Error()) + log.Fatal(err) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..557b451 --- /dev/null +++ b/go.mod @@ -0,0 +1,22 @@ +module git.espin.casa/albert/cml04-printer-robot + +go 1.21.6 + +require ( + git.espin.casa/albert/logger v0.0.0-20240130174416-19d12b345cdc + google.golang.org/grpc v1.61.0 + google.golang.org/protobuf v1.32.0 +) + +require github.com/gorilla/websocket v1.5.0 // indirect + +require ( + github.com/eclipse/paho.mqtt.golang v1.4.3 + github.com/golang/protobuf v1.5.3 // indirect + github.com/sirupsen/logrus v1.9.3 // indirect + golang.org/x/net v0.18.0 // indirect + golang.org/x/sync v0.6.0 // indirect + golang.org/x/sys v0.14.0 // indirect + golang.org/x/text v0.14.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..31d54ba --- /dev/null +++ b/go.sum @@ -0,0 +1,43 @@ +git.espin.casa/albert/logger v0.0.0-20240130174416-19d12b345cdc h1:8xlNjgJX7XQ7nxFki/e/Lga1mGuvr0A2lezdT2zmzl8= +git.espin.casa/albert/logger v0.0.0-20240130174416-19d12b345cdc/go.mod h1:dacFMi82f5ysDOaJQm0QmQaJZ7mwGFiayJ2iS+JKAfQ= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/eclipse/paho.mqtt.golang v1.4.3 h1:2kwcUGn8seMUfWndX0hGbvH8r7crgcJguQNCyp70xik= +github.com/eclipse/paho.mqtt.golang v1.4.3/go.mod h1:CSYvoAlsMkhYOXh/oKyxa8EcBci6dVkLCbo5tTC1RIE= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 h1:Jyp0Hsi0bmHXG6k9eATXoYtjd6e2UzZ1SCn/wIupY14= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:oQ5rr10WTTMvP4A36n8JpR1OrO1BEiV4f78CneXZxkA= +google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0= +google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= +google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/app/app.go b/internal/app/app.go new file mode 100644 index 0000000..55a23a5 --- /dev/null +++ b/internal/app/app.go @@ -0,0 +1,126 @@ +package app + +import ( + "flag" + "net" + "os" + "os/signal" + "syscall" + + "git.espin.casa/albert/cml04-printer-robot/internal/logging" + "git.espin.casa/albert/cml04-printer-robot/internal/server" + "git.espin.casa/albert/cml04-printer-robot/internal/service" + "git.espin.casa/albert/cml04-printer-robot/internal/vnode" + "git.espin.casa/albert/cml04-printer-robot/pkg/api" + "git.espin.casa/albert/logger" + + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" +) + +func Run() error { + // flags + apiAddr := flag.String("api", "localhost:3333", "API server address") + logLevel := flag.String("level", "debug", "log level") + mqttAddr := flag.String("mqtt_addr", "tcp://10.1.152.13:1883", "MQTT address") + mqttTopic := flag.String("mqtt_topic", "vnode/ata12/robot", "MQTT topic") + // parse flags + flag.Parse() + // setup logger + log := logger.New(os.Stdout, *logLevel) + // create log fields + logFields := logger.LogFields{ + "app_name": "cml04-printer-robot", + "debug_legel": *logLevel, + "mqtt_address": *mqttAddr, + "api_bind_address": *apiAddr, + } + // create broker + broker, err := vnode.NewBroker(*mqttAddr, log) + if err != nil { + log.Error("create new broker failed", err, logFields) + return err + } + // start broker + if err := broker.Connect(); err != nil { + log.Error("start broker failed", err, logFields) + return err + } + defer broker.Close() + // create main service + svc := service.NewService(broker) + // add logging capabilities to main service + svc = logging.NewLoggingService(svc, log) + // create data channel + dataChannel := make(chan []byte) + // create error channel + errorCallback := make(chan error) + // create done channel + done := make(chan struct{}) + // subscribe robot data topic + go broker.SubscribeToMQTTTopic(*mqttTopic, dataChannel, errorCallback, done) + // get data from channel + go func() { + for { + select { + case data := <-dataChannel: + if err := svc.RobotEventDataHandler(data); err != nil { + log.Error("error robot event handler", err, logFields) + } + case err := <-errorCallback: + log.Error("error callback", err, logFields) + case <-done: + log.Info("done callback", logFields) + } + } + }() + // create grpc server + s := grpc.NewServer() + // create api server transport + server := server.NewAPIServer(svc) + // register service + api.RegisterRobotServiceServer(s, server) + // Reflection grpc server + reflection.Register(s) + // create grpc server + lis, err := net.Listen("tcp", *apiAddr) + if err != nil { + log.Error("failed to listen", err, logFields) + return err + } + // start service server + go func() { + if err := s.Serve(lis); err != nil { + log.Error("failed to serve gRPC", err, logFields) + return + } + }() + // start banner + log.Info("cml04 printer robot service started", logFields) + // wait signal to finish + signal := WaitSignal() + // end subscriber + close(done) + log.Info("signal received", logger.LogFields{ + "signal": signal, + }) + return nil +} + +// WaitSignal catching exit signal +func WaitSignal() os.Signal { + ch := make(chan os.Signal, 2) + signal.Notify( + ch, + syscall.SIGINT, + syscall.SIGQUIT, + syscall.SIGTERM, + ) + for { + sig := <-ch + switch sig { + case syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM: + return sig + } + } +} diff --git a/internal/logging/logging.go b/internal/logging/logging.go new file mode 100644 index 0000000..3fccbe6 --- /dev/null +++ b/internal/logging/logging.go @@ -0,0 +1,52 @@ +package logging + +import ( + "context" + "time" + + "git.espin.casa/albert/cml04-printer-robot/internal/service" + "git.espin.casa/albert/cml04-printer-robot/pkg/api" + "git.espin.casa/albert/logger" +) + +type LoggingService struct { + next service.IService + log logger.LoggerAdapter +} + +// RobotEventDataHandler implements service.IService. +func (svc *LoggingService) RobotEventDataHandler(data []byte) (err error) { + defer func(start time.Time) { + fields := logger.LogFields{ + "duration": time.Since(start).String(), + } + if err != nil { + svc.log.Error("robot event handler data failed", err, fields) + } else { + svc.log.Trace("robot event handler data success", fields) + } + }(time.Now()) + return svc.next.RobotEventDataHandler(data) +} + +// PrintPackage implements service.IService. +func (svc *LoggingService) PrintPackage(ctx context.Context, req *api.PrintPackageReq) (res *api.PrintPackageRes, err error) { + defer func(start time.Time) { + fields := logger.LogFields{ + "duration": time.Since(start).String(), + } + if err != nil { + svc.log.Error("print package failed", err, fields) + } else { + svc.log.Info("print package success", fields) + } + }(time.Now()) + return svc.next.PrintPackage(ctx, req) +} + +func NewLoggingService(next service.IService, log logger.LoggerAdapter) service.IService { + return &LoggingService{ + next: next, + log: log, + } +} diff --git a/internal/server/server.go b/internal/server/server.go new file mode 100644 index 0000000..b7ea007 --- /dev/null +++ b/internal/server/server.go @@ -0,0 +1,24 @@ +package server + +import ( + "context" + + "git.espin.casa/albert/cml04-printer-robot/internal/service" + "git.espin.casa/albert/cml04-printer-robot/pkg/api" +) + +type server struct { + api.UnimplementedRobotServiceServer + svc service.IService +} + +func (s server) PrintPackage(ctx context.Context, req *api.PrintPackageReq) (res *api.PrintPackageRes, err error) { + return s.svc.PrintPackage(ctx, req) +} + +func NewAPIServer(svc service.IService) *server { + return &server{ + UnimplementedRobotServiceServer: api.UnimplementedRobotServiceServer{}, + svc: svc, + } +} diff --git a/internal/service/service.go b/internal/service/service.go new file mode 100644 index 0000000..cd74bb2 --- /dev/null +++ b/internal/service/service.go @@ -0,0 +1,342 @@ +package service + +import ( + "bytes" + "container/list" + "context" + "encoding/json" + "errors" + "fmt" + "strings" + "time" + + "git.espin.casa/albert/cml04-printer-robot/internal/vnode" + "git.espin.casa/albert/cml04-printer-robot/pkg/api" +) + +var ( + HeartBeatTime time.Time + PrintWithRobot bool + Color CardColor +) + +var ( + ErrorHeartBeat error = errors.New("heart beat time exceded") +) + +type LabelPrinter uint8 + +const ( + LabelPrinter01 LabelPrinter = iota << 2 + LabelPrinter02 + LabelPrinter03 + LabelPrinter04 + LabelPrinter05 +) + +type CardColor uint8 + +const ( + CardColorBlueYellow CardColor = iota << 2 + CardColorRed + CardColorYellow + CardColorGreen + CardColorWhite + CardColorBlue + CardColorOrange + CardColorBlack + CardColorNone +) + +type Tag struct { + Topic string `json:"t"` + Value any `json:"v"` +} + +var ( + CardColorMap = map[CardColor]*Tag{ + CardColorBlueYellow: { + Topic: "/robot12/write/blue_yellow_card", + Value: false, + }, + CardColorRed: { + Topic: "/robot12/write/red_card", + Value: false, + }, + CardColorYellow: { + Topic: "/robot12/write/yellow_card", + Value: false, + }, + CardColorGreen: { + Topic: "/robot12/write/green_card", + Value: false, + }, + CardColorWhite: { + Topic: "/robot12/write/white_card", + Value: false, + }, + CardColorBlue: { + Topic: "/robot12/write/blue_card", + Value: false, + }, + CardColorOrange: { + Topic: "/robot12/write/orange_card", + Value: false, + }, + CardColorBlack: { + Topic: "/robot12/write/black_card", + Value: false, + }, + CardColorNone: { + Topic: "/robot12/write/none_card", + Value: false, + }, + } +) + +type IService interface { + PrintPackage(ctx context.Context, req *api.PrintPackageReq) (res *api.PrintPackageRes, err error) + RobotEventDataHandler(data []byte) error +} + +type service struct { + broker *vnode.Broker + queue *list.List +} + +func (s *service) HeartBeatHandler() error { + if time.Since(HeartBeatTime) > time.Second*30 { + return ErrorHeartBeat + } + HeartBeatTime = time.Now() + return nil +} + +func (s *service) CardColor(product, po, co, grade string) error { + // grades + calidadNormal := false + calidadEspecial := false + // set grade + if strings.Contains(grade, "275") { + calidadNormal = true + } else { + calidadEspecial = true + } + // none A product + pendientes := co == fmt.Sprintf("5%s", po) + chatarra := co == fmt.Sprintf("6%s", po) + segundas := co == fmt.Sprintf("7%s", po) + cortas := co == fmt.Sprintf("8%s", po) + // pendientes + if pendientes { + return s.SetColorCard(CardColorOrange) + } + // chatarra + if chatarra { + return s.SetColorCard(CardColorRed) + } + // segundas or cortas + if segundas || cortas { + return s.SetColorCard(CardColorWhite) + } + // british + british := strings.HasPrefix(product, "UB") || strings.HasPrefix(product, "UC") || strings.HasPrefix(product, "PFC") + // american + american := strings.HasPrefix(product, "W") + // + + if calidadEspecial { + return s.SetColorCard(CardColorBlueYellow) + } else if (strings.HasPrefix(product, "HEA") || strings.HasPrefix(product, "IPEA")) && calidadNormal { + return s.SetColorCard(CardColorYellow) + } else if (strings.HasPrefix(product, "HEA") || strings.HasPrefix(product, "IPEA")) && calidadEspecial { + return s.SetColorCard(CardColorBlue) + } else if british && calidadNormal { + return s.SetColorCard(CardColorBlack) + } else if british && calidadEspecial { + noneColorLabel = true + } else if strings.HasPrefix(product, "W") { + noneColorLabel = true + } + return nil +} + +// SetColorCard set color card +func (s *service) SetColorCard(color CardColor) error { + // check color card + if selectedCard, ok := CardColorMap[color]; !ok { + return errors.New("invalid color") + } else { + selectedCard.Value = true + } + // data buffer + data := bytes.NewBuffer([]byte{}) + // tags + tags := []Tag{} + // add tags + for _, v := range CardColorMap { + tag := Tag{ + Topic: v.Topic, + Value: v.Value, + } + tags = append(tags, tag) + } + // encode color cards + if err := json.NewEncoder(data).Encode(&tags); err != nil { + return err + } + // publish color cards + if err := s.broker.Publish("vnode/test", data.Bytes()); err != nil { + return err + } + // init color cards + s.CardColorInit() + // set color + Color = color + return nil +} + +// CardColorInit init color card +func (s *service) CardColorInit() { + for _, v := range CardColorMap { + v.Value = false + } +} + +func (s *service) Enqueue(data any) { + s.queue.PushBack(data) +} + +func (s *service) Dequeue() any { + if s.queue.Len() == 0 { + return nil + } + return s.queue.Remove(s.queue.Front()) +} + +func (s *service) Peek() any { + if s.queue.Len() == 0 { + return nil + } + return s.queue.Front().Value +} + +func (s *service) QueueLen() int { + return s.queue.Len() +} + +// PrintPackage implements IService. +func (s *service) PrintPackage(ctx context.Context, req *api.PrintPackageReq) (res *api.PrintPackageRes, err error) { + s.Enqueue(req.PackageData) + return &api.PrintPackageRes{ + Msg: "print package success", + TimeStamp: time.Now().UTC().Format(time.RFC3339), + }, nil +} + +func (s *service) PrintHandler(lp LabelPrinter) error { + fmt.Println(LabelPrinter(lp)) + return nil +} + +func (s *service) ResetFifoHandler() error { + s.queue.Init() + return nil +} + +func (s *service) PrintWithRobotHandler(v bool) { + PrintWithRobot = v +} + +func (s *service) PackagePiecesHandler(pieces int64) { + fmt.Println(pieces) +} + +func (s *service) RobotEventDataHandler(data []byte) error { + rb := vnode.MqttMessage{} + if err := json.NewDecoder(bytes.NewBuffer(data)).Decode(&rb); err != nil { + return err + } + for _, msg := range rb { + switch msg.Topic { + case "/robot12/read/print_with_robot": + if v, ok := msg.Value.(bool); ok { + if v { + s.PrintWithRobotHandler(v) + } + } + case "/robot12/read/reset_fifo": + // if true + if v, ok := msg.Value.(bool); ok && v { + if v { + if err := s.ResetFifoHandler(); err != nil { + return err + } + } + } + case "/robot12/read/heart_beat": + // if true + if v, ok := msg.Value.(bool); ok && v { + if v { + if err := s.HeartBeatHandler(); err != nil { + return err + } + } + } + case "/robot12/read/print_on_paper_01": + // if true + if v, ok := msg.Value.(bool); ok && v { + if v { + if err := s.PrintHandler(LabelPrinter01); err != nil { + return err + } + } + } + case "/robot12/read/print_on_paper_02": + // if true + if v, ok := msg.Value.(bool); ok && v { + if v { + if err := s.PrintHandler(LabelPrinter02); err != nil { + return err + } + } + } + case "/robot12/read/print_on_adh_01": + // if true + if v, ok := msg.Value.(bool); ok && v { + if v { + if err := s.PrintHandler(LabelPrinter03); err != nil { + return err + } + } + } + case "/robot12/read/print_on_adh_02": + // if true + if v, ok := msg.Value.(bool); ok && v { + if v { + if err := s.PrintHandler(LabelPrinter04); err != nil { + return err + } + } + } + case "/robot12/read/package_no_pieces": + if v, ok := msg.Value.(int64); ok { + s.PackagePiecesHandler(v) + } + } + } + return nil +} + +func init() { + HeartBeatTime = time.Now() + PrintWithRobot = false +} + +func NewService(broker *vnode.Broker) IService { + queue := list.New() + return &service{ + broker: broker, + queue: queue, + } +} diff --git a/pkg/api/api.pb.go b/pkg/api/api.pb.go new file mode 100644 index 0000000..ac4666a --- /dev/null +++ b/pkg/api/api.pb.go @@ -0,0 +1,418 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.32.0 +// protoc v4.25.2 +// source: api.proto + +package api + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type PackageData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Producto string `protobuf:"bytes,1,opt,name=producto,proto3" json:"producto,omitempty"` + Colada string `protobuf:"bytes,2,opt,name=colada,proto3" json:"colada,omitempty"` + Matnr string `protobuf:"bytes,3,opt,name=matnr,proto3" json:"matnr,omitempty"` + Barras int32 `protobuf:"varint,4,opt,name=barras,proto3" json:"barras,omitempty"` + Longitud float64 `protobuf:"fixed64,5,opt,name=longitud,proto3" json:"longitud,omitempty"` + Fecha string `protobuf:"bytes,6,opt,name=fecha,proto3" json:"fecha,omitempty"` + NormaPoducto string `protobuf:"bytes,7,opt,name=norma_poducto,json=normaPoducto,proto3" json:"norma_poducto,omitempty"` + NormaCalidad string `protobuf:"bytes,8,opt,name=norma_calidad,json=normaCalidad,proto3" json:"norma_calidad,omitempty"` + NormaTolerancia string `protobuf:"bytes,9,opt,name=norma_tolerancia,json=normaTolerancia,proto3" json:"norma_tolerancia,omitempty"` + OrdenProduccion int64 `protobuf:"varint,10,opt,name=orden_produccion,json=ordenProduccion,proto3" json:"orden_produccion,omitempty"` + OrdenCliente int64 `protobuf:"varint,11,opt,name=orden_cliente,json=ordenCliente,proto3" json:"orden_cliente,omitempty"` + NroMatricula string `protobuf:"bytes,100,opt,name=nro_matricula,json=nroMatricula,proto3" json:"nro_matricula,omitempty"` +} + +func (x *PackageData) Reset() { + *x = PackageData{} + if protoimpl.UnsafeEnabled { + mi := &file_api_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PackageData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PackageData) ProtoMessage() {} + +func (x *PackageData) ProtoReflect() protoreflect.Message { + mi := &file_api_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PackageData.ProtoReflect.Descriptor instead. +func (*PackageData) Descriptor() ([]byte, []int) { + return file_api_proto_rawDescGZIP(), []int{0} +} + +func (x *PackageData) GetProducto() string { + if x != nil { + return x.Producto + } + return "" +} + +func (x *PackageData) GetColada() string { + if x != nil { + return x.Colada + } + return "" +} + +func (x *PackageData) GetMatnr() string { + if x != nil { + return x.Matnr + } + return "" +} + +func (x *PackageData) GetBarras() int32 { + if x != nil { + return x.Barras + } + return 0 +} + +func (x *PackageData) GetLongitud() float64 { + if x != nil { + return x.Longitud + } + return 0 +} + +func (x *PackageData) GetFecha() string { + if x != nil { + return x.Fecha + } + return "" +} + +func (x *PackageData) GetNormaPoducto() string { + if x != nil { + return x.NormaPoducto + } + return "" +} + +func (x *PackageData) GetNormaCalidad() string { + if x != nil { + return x.NormaCalidad + } + return "" +} + +func (x *PackageData) GetNormaTolerancia() string { + if x != nil { + return x.NormaTolerancia + } + return "" +} + +func (x *PackageData) GetOrdenProduccion() int64 { + if x != nil { + return x.OrdenProduccion + } + return 0 +} + +func (x *PackageData) GetOrdenCliente() int64 { + if x != nil { + return x.OrdenCliente + } + return 0 +} + +func (x *PackageData) GetNroMatricula() string { + if x != nil { + return x.NroMatricula + } + return "" +} + +type PrintPackageReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` + PackageData *PackageData `protobuf:"bytes,2,opt,name=package_data,json=packageData,proto3" json:"package_data,omitempty"` + TimeStamp string `protobuf:"bytes,100,opt,name=time_stamp,json=timeStamp,proto3" json:"time_stamp,omitempty"` +} + +func (x *PrintPackageReq) Reset() { + *x = PrintPackageReq{} + if protoimpl.UnsafeEnabled { + mi := &file_api_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PrintPackageReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PrintPackageReq) ProtoMessage() {} + +func (x *PrintPackageReq) ProtoReflect() protoreflect.Message { + mi := &file_api_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PrintPackageReq.ProtoReflect.Descriptor instead. +func (*PrintPackageReq) Descriptor() ([]byte, []int) { + return file_api_proto_rawDescGZIP(), []int{1} +} + +func (x *PrintPackageReq) GetSender() string { + if x != nil { + return x.Sender + } + return "" +} + +func (x *PrintPackageReq) GetPackageData() *PackageData { + if x != nil { + return x.PackageData + } + return nil +} + +func (x *PrintPackageReq) GetTimeStamp() string { + if x != nil { + return x.TimeStamp + } + return "" +} + +type PrintPackageRes struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Msg string `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"` + TimeStamp string `protobuf:"bytes,100,opt,name=time_stamp,json=timeStamp,proto3" json:"time_stamp,omitempty"` +} + +func (x *PrintPackageRes) Reset() { + *x = PrintPackageRes{} + if protoimpl.UnsafeEnabled { + mi := &file_api_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PrintPackageRes) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PrintPackageRes) ProtoMessage() {} + +func (x *PrintPackageRes) ProtoReflect() protoreflect.Message { + mi := &file_api_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PrintPackageRes.ProtoReflect.Descriptor instead. +func (*PrintPackageRes) Descriptor() ([]byte, []int) { + return file_api_proto_rawDescGZIP(), []int{2} +} + +func (x *PrintPackageRes) GetMsg() string { + if x != nil { + return x.Msg + } + return "" +} + +func (x *PrintPackageRes) GetTimeStamp() string { + if x != nil { + return x.TimeStamp + } + return "" +} + +var File_api_proto protoreflect.FileDescriptor + +var file_api_proto_rawDesc = []byte{ + 0x0a, 0x09, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x61, 0x70, 0x69, + 0x22, 0x8b, 0x03, 0x0a, 0x0b, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x44, 0x61, 0x74, 0x61, + 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x6f, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x6f, 0x12, 0x16, 0x0a, 0x06, + 0x63, 0x6f, 0x6c, 0x61, 0x64, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x6f, + 0x6c, 0x61, 0x64, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x6d, 0x61, 0x74, 0x6e, 0x72, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x05, 0x6d, 0x61, 0x74, 0x6e, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, + 0x72, 0x72, 0x61, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x61, 0x72, 0x72, + 0x61, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x01, 0x52, 0x08, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x12, 0x14, + 0x0a, 0x05, 0x66, 0x65, 0x63, 0x68, 0x61, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x66, + 0x65, 0x63, 0x68, 0x61, 0x12, 0x23, 0x0a, 0x0d, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x5f, 0x70, 0x6f, + 0x64, 0x75, 0x63, 0x74, 0x6f, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x6e, 0x6f, 0x72, + 0x6d, 0x61, 0x50, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x6f, 0x12, 0x23, 0x0a, 0x0d, 0x6e, 0x6f, 0x72, + 0x6d, 0x61, 0x5f, 0x63, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0c, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x43, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x64, 0x12, 0x29, + 0x0a, 0x10, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x5f, 0x74, 0x6f, 0x6c, 0x65, 0x72, 0x61, 0x6e, 0x63, + 0x69, 0x61, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x54, + 0x6f, 0x6c, 0x65, 0x72, 0x61, 0x6e, 0x63, 0x69, 0x61, 0x12, 0x29, 0x0a, 0x10, 0x6f, 0x72, 0x64, + 0x65, 0x6e, 0x5f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x63, 0x69, 0x6f, 0x6e, 0x18, 0x0a, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x0f, 0x6f, 0x72, 0x64, 0x65, 0x6e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, + 0x63, 0x69, 0x6f, 0x6e, 0x12, 0x23, 0x0a, 0x0d, 0x6f, 0x72, 0x64, 0x65, 0x6e, 0x5f, 0x63, 0x6c, + 0x69, 0x65, 0x6e, 0x74, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x6f, 0x72, 0x64, + 0x65, 0x6e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x6e, 0x72, 0x6f, + 0x5f, 0x6d, 0x61, 0x74, 0x72, 0x69, 0x63, 0x75, 0x6c, 0x61, 0x18, 0x64, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0c, 0x6e, 0x72, 0x6f, 0x4d, 0x61, 0x74, 0x72, 0x69, 0x63, 0x75, 0x6c, 0x61, 0x22, 0x7d, + 0x0a, 0x0f, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x52, 0x65, + 0x71, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x06, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x12, 0x33, 0x0a, 0x0c, 0x70, 0x61, 0x63, + 0x6b, 0x61, 0x67, 0x65, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x10, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x44, 0x61, 0x74, + 0x61, 0x52, 0x0b, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1d, + 0x0a, 0x0a, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x64, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x42, 0x0a, + 0x0f, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, + 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, + 0x73, 0x67, 0x12, 0x1d, 0x0a, 0x0a, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x18, 0x64, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x6d, + 0x70, 0x32, 0x4a, 0x0a, 0x0c, 0x52, 0x6f, 0x62, 0x6f, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x12, 0x3a, 0x0a, 0x0c, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, + 0x65, 0x12, 0x14, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x50, 0x61, 0x63, + 0x6b, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x14, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x50, 0x72, + 0x69, 0x6e, 0x74, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x42, 0x37, 0x5a, + 0x35, 0x67, 0x69, 0x74, 0x2e, 0x65, 0x73, 0x70, 0x69, 0x6e, 0x2e, 0x63, 0x61, 0x73, 0x61, 0x2f, + 0x61, 0x6c, 0x62, 0x65, 0x72, 0x74, 0x2f, 0x63, 0x6d, 0x6c, 0x30, 0x34, 0x2d, 0x70, 0x72, 0x69, + 0x6e, 0x74, 0x65, 0x72, 0x2d, 0x72, 0x6f, 0x62, 0x6f, 0x74, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x61, + 0x70, 0x69, 0x3b, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_api_proto_rawDescOnce sync.Once + file_api_proto_rawDescData = file_api_proto_rawDesc +) + +func file_api_proto_rawDescGZIP() []byte { + file_api_proto_rawDescOnce.Do(func() { + file_api_proto_rawDescData = protoimpl.X.CompressGZIP(file_api_proto_rawDescData) + }) + return file_api_proto_rawDescData +} + +var file_api_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_api_proto_goTypes = []interface{}{ + (*PackageData)(nil), // 0: api.PackageData + (*PrintPackageReq)(nil), // 1: api.PrintPackageReq + (*PrintPackageRes)(nil), // 2: api.PrintPackageRes +} +var file_api_proto_depIdxs = []int32{ + 0, // 0: api.PrintPackageReq.package_data:type_name -> api.PackageData + 1, // 1: api.RobotService.PrintPackage:input_type -> api.PrintPackageReq + 2, // 2: api.RobotService.PrintPackage:output_type -> api.PrintPackageRes + 2, // [2:3] is the sub-list for method output_type + 1, // [1:2] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_api_proto_init() } +func file_api_proto_init() { + if File_api_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_api_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PackageData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_api_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PrintPackageReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_api_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PrintPackageRes); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_api_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_api_proto_goTypes, + DependencyIndexes: file_api_proto_depIdxs, + MessageInfos: file_api_proto_msgTypes, + }.Build() + File_api_proto = out.File + file_api_proto_rawDesc = nil + file_api_proto_goTypes = nil + file_api_proto_depIdxs = nil +} diff --git a/pkg/api/api.proto b/pkg/api/api.proto new file mode 100644 index 0000000..e4ad009 --- /dev/null +++ b/pkg/api/api.proto @@ -0,0 +1,33 @@ +syntax = "proto3"; +package api; +option go_package = "git.espin.casa/albert/cml04-printer-robot/pkg/api;api"; + +service RobotService { + rpc PrintPackage (PrintPackageReq) returns (PrintPackageRes); +} + +message PackageData{ + string producto = 1; + string colada = 2; + string matnr = 3; + int32 barras = 4; + double longitud = 5; + string fecha = 6; + string norma_poducto = 7; + string norma_calidad = 8; + string norma_tolerancia = 9; + int64 orden_produccion = 10; + int64 orden_cliente = 11; + string nro_matricula = 100; +} + +message PrintPackageReq{ + string sender = 1; + PackageData package_data = 2; + string time_stamp = 100; +} + +message PrintPackageRes{ + string msg = 1; + string time_stamp = 100; +} \ No newline at end of file diff --git a/pkg/api/api_grpc.pb.go b/pkg/api/api_grpc.pb.go new file mode 100644 index 0000000..caa1804 --- /dev/null +++ b/pkg/api/api_grpc.pb.go @@ -0,0 +1,109 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v4.25.2 +// source: api.proto + +package api + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + RobotService_PrintPackage_FullMethodName = "/api.RobotService/PrintPackage" +) + +// RobotServiceClient is the client API for RobotService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type RobotServiceClient interface { + PrintPackage(ctx context.Context, in *PrintPackageReq, opts ...grpc.CallOption) (*PrintPackageRes, error) +} + +type robotServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewRobotServiceClient(cc grpc.ClientConnInterface) RobotServiceClient { + return &robotServiceClient{cc} +} + +func (c *robotServiceClient) PrintPackage(ctx context.Context, in *PrintPackageReq, opts ...grpc.CallOption) (*PrintPackageRes, error) { + out := new(PrintPackageRes) + err := c.cc.Invoke(ctx, RobotService_PrintPackage_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// RobotServiceServer is the server API for RobotService service. +// All implementations must embed UnimplementedRobotServiceServer +// for forward compatibility +type RobotServiceServer interface { + PrintPackage(context.Context, *PrintPackageReq) (*PrintPackageRes, error) + mustEmbedUnimplementedRobotServiceServer() +} + +// UnimplementedRobotServiceServer must be embedded to have forward compatible implementations. +type UnimplementedRobotServiceServer struct { +} + +func (UnimplementedRobotServiceServer) PrintPackage(context.Context, *PrintPackageReq) (*PrintPackageRes, error) { + return nil, status.Errorf(codes.Unimplemented, "method PrintPackage not implemented") +} +func (UnimplementedRobotServiceServer) mustEmbedUnimplementedRobotServiceServer() {} + +// UnsafeRobotServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to RobotServiceServer will +// result in compilation errors. +type UnsafeRobotServiceServer interface { + mustEmbedUnimplementedRobotServiceServer() +} + +func RegisterRobotServiceServer(s grpc.ServiceRegistrar, srv RobotServiceServer) { + s.RegisterService(&RobotService_ServiceDesc, srv) +} + +func _RobotService_PrintPackage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(PrintPackageReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(RobotServiceServer).PrintPackage(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: RobotService_PrintPackage_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RobotServiceServer).PrintPackage(ctx, req.(*PrintPackageReq)) + } + return interceptor(ctx, in, info, handler) +} + +// RobotService_ServiceDesc is the grpc.ServiceDesc for RobotService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var RobotService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "api.RobotService", + HandlerType: (*RobotServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "PrintPackage", + Handler: _RobotService_PrintPackage_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "api.proto", +} diff --git a/pkg/api/generate.go b/pkg/api/generate.go new file mode 100644 index 0000000..113f504 --- /dev/null +++ b/pkg/api/generate.go @@ -0,0 +1,3 @@ +package api + +//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative api.proto