Skip to content

Commit

Permalink
Merge pull request #322 from JayKaku/feature/grpc-version-echo-apis
Browse files Browse the repository at this point in the history
Implement gRPC for `echo` and `version` APIs
  • Loading branch information
stefanprodan authored Feb 25, 2024
2 parents dc830d0 + 2251bee commit 532db40
Show file tree
Hide file tree
Showing 53 changed files with 1,284 additions and 89 deletions.
10 changes: 6 additions & 4 deletions cmd/podinfo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

"github.com/stefanprodan/podinfo/pkg/api"
"github.com/stefanprodan/podinfo/pkg/grpc"
"github.com/stefanprodan/podinfo/pkg/api/grpc"
"github.com/stefanprodan/podinfo/pkg/api/http"
"github.com/stefanprodan/podinfo/pkg/signals"
"github.com/stefanprodan/podinfo/pkg/version"
go_grpc "google.golang.org/grpc"
Expand Down Expand Up @@ -138,11 +138,13 @@ func main() {
var grpcServer *go_grpc.Server
if grpcCfg.Port > 0 {
grpcSrv, _ := grpc.NewServer(&grpcCfg, logger)
//grpcinfoSrv, _ := grpc.NewInfoServer(&grpcCfg)

grpcServer = grpcSrv.ListenAndServe()
}

// load HTTP server config
var srvCfg api.Config
var srvCfg http.Config
if err := viper.Unmarshal(&srvCfg); err != nil {
logger.Panic("config unmarshal failed", zap.Error(err))
}
Expand All @@ -155,7 +157,7 @@ func main() {
)

// start HTTP server
srv, _ := api.NewServer(&srvCfg, logger)
srv, _ := http.NewServer(&srvCfg, logger)
httpServer, httpsServer, healthy, ready := srv.ListenAndServe()

// graceful shutdown
Expand Down
20 changes: 20 additions & 0 deletions pkg/api/grpc/echo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package grpc

import (
"context"

"github.com/stefanprodan/podinfo/pkg/api/grpc/echo"
"go.uber.org/zap"
)

type echoServer struct {
echo.UnimplementedEchoServiceServer
config *Config
logger *zap.Logger
}

func (s *echoServer) Echo (ctx context.Context, message *echo.Message) (*echo.Message, error){

s.logger.Info("Received message body from client:", zap.String("input body", message.Body))
return &echo.Message {Body: message.Body}, nil
}
146 changes: 146 additions & 0 deletions pkg/api/grpc/echo/echo.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions pkg/api/grpc/echo/echo.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";

option go_package = "./echo";

package echo;

message Message {
string body = 1;
}


service EchoService {
rpc Echo(Message) returns (Message) {}
}
109 changes: 109 additions & 0 deletions pkg/api/grpc/echo/echo_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 532db40

Please sign in to comment.