core

package
v0.0.0-...-e08653f Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package core provides the core setting for the application.

Index

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

func UseAfter

func UseAfter(fn func(ctx context.Context) error)

UseAfter adds a hook to be executed after the application has stopped.

func UseBefore

func UseBefore(fn func(ctx context.Context) error)

UseBefore uses the given function before the application starts.

Types

type Application

type Application interface {
	Start(ctx context.Context) error
}

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

func NewEdge

func NewEdge(opts ...runtime.ServeMuxOption) Edge

NewEdge creates a new http server.

type EdgeConfig

type EdgeConfig struct {
	Addr    string
	Handler http.Handler
}

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

type ServiceInfo struct {
	Config *types.Config
	Addr   string
	Tags   []string
	Name   string
}

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.

Directories

Path Synopsis
Package coreinternal provides the internal function for the core.
Package coreinternal provides the internal function for the core.
Package net provide functions extended of http/net
Package net provide functions extended of http/net

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳