app

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2025 License: BSD-3-Clause Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHttpServer added in v0.1.2

func NewHttpServer(register func(e *gin.Engine, a *AppOptions), opts *AppOptions) server.Server

Types

type App

type App struct {
	AppOptions
	// contains filtered or unexported fields
}

func New

func New[T any](configPath string, opts ...AppOption) *App

func (*App) Run

func (a *App) Run() error

Run run server 1.注册服务 2.退出相关组件或服务

func (*App) Stop

func (a *App) Stop()

Stop 手动停止服务

type AppOption added in v0.1.2

type AppOption func(o *AppOptions)

func WithAfterStart added in v0.1.2

func WithAfterStart(fn func(ctx context.Context, opts *AppOptions) error) AppOption

func WithAfterStop added in v0.1.2

func WithAfterStop(fn func(ctx context.Context, opts *AppOptions) error) AppOption

func WithAppID

func WithAppID(id string) AppOption

func WithBeforeStart added in v0.1.2

func WithBeforeStart(fn func(ctx context.Context) error) AppOption

func WithBeforeStop added in v0.1.2

func WithBeforeStop(fn func(ctx context.Context, opts *AppOptions) error) AppOption

func WithEndpoints

func WithEndpoints(endpoints []*url.URL) AppOption

func WithGinServer

func WithGinServer(svr func(e *gin.Engine, a *AppOptions)) AppOption

func WithGrpcServer

func WithGrpcServer(svr func(s *grpc.Server, a *AppOptions), grpcServerOpts ...grpc.ServerOption) AppOption

func WithMustDB

func WithMustDB() AppOption

func WithMustRedis

func WithMustRedis() AppOption

func WithRegistrar

func WithRegistrar(registrar registry.ServiceRegistrar) AppOption

func WithServer added in v0.1.2

func WithServer(name string, srv func(a *AppOptions) server.Server) AppOption

WithServer 注入 server, 需要指定唯一的key

func WithSignal

func WithSignal(sigs []os.Signal) AppOption

type AppOptions added in v0.1.2

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

func (*AppOptions) AppID added in v0.1.2

func (o *AppOptions) AppID() string

AppID 获取应用程序启动实例ID

func (*AppOptions) Conf added in v0.1.2

func (o *AppOptions) Conf() *conf.Basic

Conf 获取公共配置(eg app info、logger config、db config 、redis config)

func (*AppOptions) DB added in v0.1.2

func (o *AppOptions) DB() *db.DBManager

DB 获取数据库连接 DB gorm 关系型数据库 -- 持久化

func (*AppOptions) LocalCache added in v0.1.2

func (o *AppOptions) LocalCache() cache.Cache

LocalCache 获取本地缓存 1.一级缓存 变动小、容量少。容量固定,有淘汰策略。 2.不适合分布式数据共享。

func (*AppOptions) Redis added in v0.1.2

func (o *AppOptions) Redis() redis.UniversalClient

Redis 获取redis client CacheDB 二级缓存 容量大,有网络IO延迟

func (*AppOptions) Server added in v0.1.2

func (o *AppOptions) Server(name string) (any, bool)

Server 获取自己注入的组件服务

type HttpServer added in v0.1.2

type HttpServer struct {
	Opts       *AppOptions
	RegistryFn func(e *gin.Engine, a *AppOptions)
	// contains filtered or unexported fields
}

func (*HttpServer) Get added in v0.1.2

func (srv *HttpServer) Get(name string) any

func (*HttpServer) Start added in v0.1.2

func (srv *HttpServer) Start(ctx context.Context) error

func (*HttpServer) Stop added in v0.1.2

func (srv *HttpServer) Stop(ctx context.Context) error

type RpcServer added in v0.1.2

type RpcServer struct {
	Opts       *AppOptions
	RegistryFn func(s *grpc.Server, a *AppOptions)
	// contains filtered or unexported fields
}

func NewRpcServer added in v0.1.2

func NewRpcServer(registry func(s *grpc.Server, a *AppOptions), opts *AppOptions, grpcServerOpts ...grpc.ServerOption) *RpcServer

func (*RpcServer) Get added in v0.1.2

func (srv *RpcServer) Get(name string) any

func (*RpcServer) Start added in v0.1.2

func (srv *RpcServer) Start(ctx context.Context) error

func (*RpcServer) Stop added in v0.1.2

func (srv *RpcServer) Stop(ctx context.Context) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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