server

package
v1.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2025 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var App = fx.Options(
	fx.Module(
		module,
		fx.Decorate(
			func(l logger.Logger) logger.Logger {
				return l.WithScope(module)
			},
		),

		fx.Provide(
			func(c config.Config) (keyfunc.Keyfunc, error) {
				return keyfunc.NewDefault([]string{c.JWKS_URL})
			},
			jwt.NewManager,
		),

		fx.Provide(
			interceptor.NewAuth,

			fx.Annotate(service.NewVsApiV1, fx.As(new(v1.VintageServiceServer))),
			New,
		),

		fx.Invoke(
			func(lc fx.Lifecycle, log logger.Logger, c config.Config, server *Server) {
				lc.Append(
					fx.Hook{
						OnStart: func(ctx context.Context) error {
							go func() {
								addr := fmt.Sprintf(":%d", c.GrpcPort)
								err := server.Run(context.Background(), "tcp", addr)
								if err != nil {
									log.Error("server stopped", zap.Error(err))
								}
							}()

							go func() {
								grpcaddr := fmt.Sprintf(":%d", c.GrpcPort)
								addr := fmt.Sprintf(":%d", c.GateAwayPort)
								err := server.RunInProcessGateway(
									context.Background(),
									grpcaddr,
									addr,
									runtime.WithMarshalerOption(
										runtime.MIMEWildcard, &runtime.JSONPb{
											MarshalOptions: protojson.MarshalOptions{
												UseProtoNames:     true,
												EmitDefaultValues: true,
											},
											UnmarshalOptions: protojson.UnmarshalOptions{},
										},
									),
								)
								if err != nil {
									log.Error("gw server stopped", zap.Error(err))
								}
							}()

							log.Info("server started", zap.String("port", strconv.Itoa(c.GrpcPort)))
							return nil
						},
						OnStop: func(ctx context.Context) error {
							log.Info("gracefully stopping grpc server...")
							server.GracefulStop(context.Background())

							log.Info("server stopped")
							return nil
						},
					},
				)
			},
		),
	),
)

Functions

This section is empty.

Types

type Server added in v1.5.0

type Server struct {
	// contains filtered or unexported fields
}

func New

func New(opts Opts) *Server

func (*Server) GracefulStop added in v1.5.0

func (s *Server) GracefulStop(ctx context.Context)

func (*Server) Run added in v1.5.0

func (s *Server) Run(ctx context.Context, network, address string) error

func (*Server) RunInProcessGateway added in v1.5.0

func (s *Server) RunInProcessGateway(ctx context.Context, grpcaddr, addr string, opts ...runtime.ServeMuxOption) error

RunInProcessGateway starts the invoke in process http gateway.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL