refactor(runtime/v2): simplify app manager (#22300)

This commit is contained in:
Julien Robert
2024-10-21 13:45:28 +00:00
committed by GitHub
parent 97d37ae243
commit 681366e346
22 changed files with 202 additions and 200 deletions
+3 -3
View File
@@ -57,14 +57,14 @@ func (s *Server[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.L
return fmt.Errorf("failed to unmarshal config: %w", err)
}
}
methodsMap := appI.GetQueryHandlers()
methodsMap := appI.QueryHandlers()
grpcSrv := grpc.NewServer(
grpc.ForceServerCodec(newProtoCodec(appI.InterfaceRegistry()).GRPCCodec()),
grpc.MaxSendMsgSize(serverCfg.MaxSendMsgSize),
grpc.MaxRecvMsgSize(serverCfg.MaxRecvMsgSize),
grpc.UnknownServiceHandler(
makeUnknownServiceHandler(methodsMap, appI.GetAppManager()),
makeUnknownServiceHandler(methodsMap, appI),
),
)
@@ -85,7 +85,7 @@ func (s *Server[T]) StartCmdFlags() *pflag.FlagSet {
}
func makeUnknownServiceHandler(handlers map[string]appmodulev2.Handler, querier interface {
Query(ctx context.Context, version uint64, msg gogoproto.Message) (gogoproto.Message, error)
Query(ctx context.Context, version uint64, msg transaction.Msg) (transaction.Msg, error)
},
) grpc.StreamHandler {
getRegistry := sync.OnceValues(gogoproto.MergedRegistry)
+2 -2
View File
@@ -20,12 +20,12 @@ const (
MaxBodySize = 1 << 20 // 1 MB
)
func NewDefaultHandler[T transaction.Tx](appManager *appmanager.AppManager[T]) http.Handler {
func NewDefaultHandler[T transaction.Tx](appManager appmanager.AppManager[T]) http.Handler {
return &DefaultHandler[T]{appManager: appManager}
}
type DefaultHandler[T transaction.Tx] struct {
appManager *appmanager.AppManager[T]
appManager appmanager.AppManager[T]
}
func (h *DefaultHandler[T]) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+1 -1
View File
@@ -45,7 +45,7 @@ func (s *Server[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.L
}
s.router = http.NewServeMux()
s.router.Handle("/", NewDefaultHandler(appI.GetAppManager()))
s.router.Handle("/", NewDefaultHandler(appI))
s.config = serverCfg
return nil