framework

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module fx.Option = fx.Module(
	"framework",
	fx.Provide(func(ev *env.Env) *fm {
		return &fm{Env: ev}
	}),
	repos.NewMongoClientFx[*fm](),

	fx.Provide(func(logger *slog.Logger, ev *env.Env) (app.IAMGrpcServer, error) {
		return grpc.NewGrpcServer(grpc.ServerOpts{Logger: logger, ShowLogs: ev.ShowGRPCLogs})
	}),

	app.Module,

	fx.Invoke(func(lf fx.Lifecycle, server app.IAMGrpcServer, ev *env.Env) {
		lf.Append(fx.Hook{
			OnStart: func(ctx context.Context) error {
				timeout, cf := context.WithTimeout(ctx, 2*time.Second)
				defer cf()
				errCh := make(chan error, 1)
				go func() {
					if err := server.Listen(fmt.Sprintf(":%d", ev.GrpcPort)); err != nil {
						errCh <- err
					}
				}()

				select {
				case <-timeout.Done():
				case err := <-errCh:
					return errors.NewE(err)
				}
				return nil
			},

			OnStop: func(ctx context.Context) error {
				server.Stop()
				return nil
			},
		})
	}),
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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