Documentation
¶
Index ¶
- func NewHttpServer(register func(e *gin.Engine, a *AppOptions), opts *AppOptions) server.Server
- type App
- type AppOption
- func WithAfterStart(fn func(ctx context.Context, opts *AppOptions) error) AppOption
- func WithAfterStop(fn func(ctx context.Context, opts *AppOptions) error) AppOption
- func WithAppID(id string) AppOption
- func WithBeforeStart(fn func(ctx context.Context) error) AppOption
- func WithBeforeStop(fn func(ctx context.Context, opts *AppOptions) error) AppOption
- func WithEndpoints(endpoints []*url.URL) AppOption
- func WithGatewayServer(handlerFunc func(mux *runtime.ServeMux), muxs ...runtime.ServeMuxOption) AppOption
- func WithGinServer(svr func(e *gin.Engine, a *AppOptions)) AppOption
- func WithGrpcServer(svr func(s *grpc.Server, a *AppOptions), grpcServerOpts ...grpc.ServerOption) AppOption
- func WithKafka(subs ...kafka.Subscriber) AppOption
- func WithMustDB(drivers ...db.DriverOpenFunc) AppOption
- func WithMustRedis() AppOption
- func WithRegistrar(registrar registry.ServiceRegistrar) AppOption
- func WithServer(name string, srv func(a *AppOptions) server.Server) AppOption
- func WithSignal(sigs []os.Signal) AppOption
- type AppOptions
- type HttpServer
- type RpcServer
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
}
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 WithBeforeStart ¶ added in v0.1.2
WithBeforeStart 在启动前执行(可以传多次)
func WithBeforeStop ¶ added in v0.1.2
func WithBeforeStop(fn func(ctx context.Context, opts *AppOptions) error) AppOption
WithBeforeStop 在停止前执行(可以传多次)
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 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
type AppOptions ¶ added in v0.1.2
type AppOptions struct {
// contains filtered or unexported fields
}
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延迟
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
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