app

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: BSD-3-Clause Imports: 50 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

WithAfterStart 在启动后执行(可以传多次)

func WithAfterStop added in v0.1.2

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

WithAfterStop 在停止后执行(可以传多次)

func WithAppID

func WithAppID(id string) AppOption

WithAppID 设置appID,默认UUID

func WithBeforeStart added in v0.1.2

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

WithBeforeStart 在启动前执行(可以传多次)

func WithBeforeStop added in v0.1.2

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

WithBeforeStop 在停止前执行(可以传多次)

func WithEndpoints

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

WithEndpoints 设置服务地址

func WithGatewayServer added in v0.1.4

func WithGatewayServer(handlerFunc func(mux *runtime.ServeMux), muxs ...runtime.ServeMuxOption) AppOption

WithCache 使用GrpcGateway reg 注册服务 grpcServerOpts 可选的 grpc server options

func WithGinServer

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

WithGinServer 使用 gin server srv 注册路由,添加 handler

func WithGrpcServer

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

WithGrpcServer 使用 grpc server srv 注册业务服务(pb生成) grpcServerOpts 可选的 grpc server options

func WithKafka added in v0.1.3

func WithKafka(subs ...kafka.Subscriber) AppOption

WithKafka 使用 Kafka server subs 注册消息处理器

func WithMustDB

func WithMustDB(drivers ...db.DriverOpenFunc) AppOption

WithMustDB 初始化数据库组件(错误直接panic) GORM 官方支持的数据库类型有 MySQL, PostgreSQL, SQLite, SQL Server 和 TiDB

func WithMustRedis

func WithMustRedis() AppOption

WithMustRedis 初始化 Redis 组件(错误直接panic)

func WithRegistrar

func WithRegistrar(registrar registry.ServiceRegistrar) AppOption

WithRegistrar 设置服务注册器

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

WithSignal 设置可监听的退出信号

func WithTracerServer added in v0.1.6

func WithTracerServer() AppOption

WithTracerServer 使用 TracerServer

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() cache.RedisManager

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() 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() 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

Jump to

Keyboard shortcuts

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