Skip to content

Commit

Permalink
Merge pull request #369 from Prashant-Dwivedi-08-01/grpc_APIs
Browse files Browse the repository at this point in the history
GRPC Apis for Corresponding HTTP APIs
  • Loading branch information
stefanprodan committed Jun 23, 2024
2 parents 5fb6597 + b10c306 commit 752950c
Show file tree
Hide file tree
Showing 39 changed files with 2,943 additions and 68 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ gRPC API:
* `/grpc.health.v1.Health/Check` health checking
* `/grpc.EchoService/Echo` echos the received content
* `/grpc.VersionService/Version` returns podinfo version and Git commit hash
* `/grpc.DelayService/Delay` returns a successful response after the given seconds in the body of gRPC request
* `/grpc.EnvService/Env` returns environment variables as a JSON array
* `/grpc.HeaderService/Header` returns the headers present in the gRPC request. Any custom header can also be given as a part of request and that can be returned using this API
* `/grpc.InfoService/Info` returns the runtime information
* `/grpc.PanicService/Panic` crashes the process with gRPC status code as '1 CANCELLED'
* `/grpc.StatusService/Status` returns the gRPC Status code given in the request body
* `/grpc.TokenService/TokenGenerate` issues a JWT token valid for one minute
* `/grpc.TokenService/TokenValidate` validates the JWT token

Web UI:

Expand Down
2 changes: 1 addition & 1 deletion cmd/podinfo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func main() {
if grpcCfg.Port > 0 {
grpcSrv, _ := grpc.NewServer(&grpcCfg, logger)
//grpcinfoSrv, _ := grpc.NewInfoServer(&grpcCfg)

grpcServer = grpcSrv.ListenAndServe()
}

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

import (
"context"
"time"

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

type DelayServer struct {
pb.UnimplementedDelayServiceServer
config *Config
logger *zap.Logger
}

func (s *DelayServer) Delay(ctx context.Context, delayInput *pb.DelayRequest) (*pb.DelayResponse, error) {

time.Sleep(time.Duration(delayInput.Seconds) * time.Second)
return &pb.DelayResponse{Message: delayInput.Seconds}, nil
}
211 changes: 211 additions & 0 deletions pkg/api/grpc/delay/delay.pb.go

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

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

option go_package = "./delay";

package delay;

message DelayRequest {
int64 seconds = 1;
}

message DelayResponse {
int64 message = 1;
}

service DelayService {
rpc Delay (DelayRequest) returns (DelayResponse) {}
}
105 changes: 105 additions & 0 deletions pkg/api/grpc/delay/delay_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 752950c

Please sign in to comment.