Documentation
¶
Overview ¶
Package core provides the core setting for the application.
Index ¶
- func Inject[fn any](constructor fn) fn
- func InjectLifeCycle[T any](constructor func() T, onStart func(T) error, onStop func(T) error) func() T
- func RegisterService(ctx context.Context, edge Edge, service GRPCService, endpoint string, ...) error
- func UseAfter(fn func(ctx context.Context) error)
- func UseBefore(fn func(ctx context.Context) error)
- type Application
- type Edge
- type EdgeConfig
- type GRPCService
- type IServiceServer
- type Server
- type ServiceInfo
- type ServiceServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Inject ¶
func Inject[fn any](constructor fn) fn
Inject injects the given constructor into the application.
func InjectLifeCycle ¶
func InjectLifeCycle[T any](constructor func() T, onStart func(T) error, onStop func(T) error) func() T
InjectLifeCycle injects the given constructor into the application with lifecycle hooks.
func RegisterService ¶
func RegisterService(ctx context.Context, edge Edge, service GRPCService, endpoint string, opts []grpc.DialOption) error
RegisterService registers a service with the runtime. The service is registered with the runtime mux.
dependency:
- github.com/grpc-ecosystem/grpc-gateway/v2/runtime
Types ¶
type Application ¶
Application represents the application when all constructor was build by core.Build() start the app, it will start the server and provide all constructor needed
func Build ¶
func Build(constructors ...interface{}) Application
Build builds the application. The application is built by providing the constructors.
type Edge ¶
type Edge interface { Listen(conf *EdgeConfig) error AsRuntimeMux() *runtime.ServeMux AsMux() *http.ServeMux }
Edge is an interface for a runtime mux with http server. default port is 9000
type EdgeConfig ¶
EdgeConfig is properties of Edge.Listen function, include address and http handler response
type GRPCService ¶
type GRPCService interface {
Register(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error
}
GRPCService is an interface for registering a gRPC service.
usage:
type IService interface { core.GRPCService }
type IServiceServer ¶
type IServiceServer interface { AsServer() *grpc.Server Serve(info *ServiceInfo) error }
IServiceServer is a gRPC service server.
type Server ¶
type Server interface {
ListenAndServe() error
}
Server represents the HTTP/gRPC server interface.
type ServiceInfo ¶
ServiceInfo is Serve method properties
type ServiceServer ¶
type ServiceServer struct {
// contains filtered or unexported fields
}
ServiceServer is a gRPC server that registers services.
usage:
type Greeter struct { *core.ServiceServer config *types.Config srv greeter.GreeterServiceServer }
func New ¶
func New(opts ...grpc.ServerOption) *ServiceServer
New returns a new service registrar. opts are the gRPC server options.
func NewDefault ¶
func NewDefault() *ServiceServer
NewDefault returns a new service registrar with default options.
func (*ServiceServer) AsServer ¶
func (s *ServiceServer) AsServer() *grpc.Server
AsServer returns the underlying gRPC server. return the underlying gRPC server.
func (*ServiceServer) Serve ¶
func (s *ServiceServer) Serve(info *ServiceInfo) error
Serve starts the http server. return error if the http server fails to start.