refactor(server/v2): add missing comet flags (#21123)

This commit is contained in:
Julien Robert
2024-07-31 15:58:50 +00:00
committed by GitHub
parent 453c86ebf1
commit 98e09a720d
15 changed files with 70 additions and 50 deletions
+12
View File
@@ -0,0 +1,12 @@
package grpc
import "fmt"
// start flags are prefixed with the server name
// as the config in prefixed with the server name
// this allows viper to properly bind the flags
func prefix(f string) string {
return fmt.Sprintf("%s.%s", ServerName, f)
}
var FlagAddress = prefix("address")
+5 -12
View File
@@ -24,8 +24,9 @@ import (
)
const (
ServerName = "grpc"
BlockHeightHeader = "x-cosmos-block-height"
FlagAddress = "address"
)
type Server[T transaction.Tx] struct {
@@ -74,16 +75,8 @@ func (s *Server[T]) Init(appI serverv2.AppI[T], v *viper.Viper, logger log.Logge
}
func (s *Server[T]) StartCmdFlags() *pflag.FlagSet {
flags := pflag.NewFlagSet("grpc", pflag.ExitOnError)
// start flags are prefixed with the server name
// as the config in prefixed with the server name
// this allows viper to properly bind the flags
prefix := func(f string) string {
return fmt.Sprintf("%s.%s", s.Name(), f)
}
flags.String(prefix(FlagAddress), "localhost:9090", "Listen address")
flags := pflag.NewFlagSet(s.Name(), pflag.ExitOnError)
flags.String(FlagAddress, "localhost:9090", "Listen address")
return flags
}
@@ -151,7 +144,7 @@ func getHeightFromCtx(ctx context.Context) (uint64, error) {
}
func (s *Server[T]) Name() string {
return "grpc"
return ServerName
}
func (s *Server[T]) Config() any {
+3 -1
View File
@@ -21,6 +21,8 @@ import (
var _ serverv2.ServerComponent[transaction.Tx] = (*GRPCGatewayServer[transaction.Tx])(nil)
const (
ServerName = "grpc-gateway"
// GRPCBlockHeightHeader is the gRPC header for block height.
GRPCBlockHeightHeader = "x-cosmos-block-height"
)
@@ -64,7 +66,7 @@ func New[T transaction.Tx](grpcSrv *grpc.Server, ir jsonpb.AnyResolver, cfgOptio
}
func (g *GRPCGatewayServer[T]) Name() string {
return "grpc-gateway"
return ServerName
}
func (s *GRPCGatewayServer[T]) Config() any {