Documentation
¶
Index ¶
- func NewCache(prefix string, store storage.AdapterCache, wxTokenStoreKey string) storage.AdapterCache
- func NewLocker(prefix string, locker storage.AdapterLocker) storage.AdapterLocker
- func NewQueue(prefix string, queue storage.AdapterQueue) storage.AdapterQueue
- type Application
- func (e *Application) GetAppRouters() []func()
- func (e *Application) GetCacheAdapter() storage.AdapterCache
- func (e *Application) GetCachePrefix(key string) storage.AdapterCache
- func (e *Application) GetCasbins(fn func(tenantID string, enforcer *casbin.SyncedEnforcer) bool)
- func (e *Application) GetConfig(key string) interface{}
- func (e *Application) GetCrontabs(fn func(tenantID string, crontab *cron.Cron) bool)
- func (e *Application) GetEngine() http.Handler
- func (e *Application) GetEventBus() eventbus.EventBus
- func (e *Application) GetHandler() map[string][]func(r *gin.RouterGroup, hand ...*gin.HandlerFunc)
- func (e *Application) GetHandlerPrefix(key string) []func(r *gin.RouterGroup, hand ...*gin.HandlerFunc)
- func (e *Application) GetLockerAdapter() storage.AdapterLocker
- func (e *Application) GetLockerPrefix(key string) storage.AdapterLocker
- func (e *Application) GetLogger() *zap.Logger
- func (e *Application) GetMemoryQueue(prefix string) storage.AdapterQueue
- func (e *Application) GetMiddleware() map[string]interface{}
- func (e *Application) GetMiddlewareKey(key string) interface{}
- func (e *Application) GetQueueAdapter() storage.AdapterQueue
- func (e *Application) GetQueuePrefix(key string) storage.AdapterQueue
- func (e *Application) GetRouter() []Router
- func (e *Application) GetStreamMessage(id, stream string, value map[string]interface{}) (storage.Messager, error)
- func (e *Application) GetTenantCasbin(tenantID string) *casbin.SyncedEnforcer
- func (e *Application) GetTenantCommandDB(tenantID string) *gorm.DB
- func (e *Application) GetTenantCommandDBs(fn func(tenantID string, db *gorm.DB) bool)
- func (e *Application) GetTenantCrontab(tenantID string) *cron.Cron
- func (e *Application) GetTenantDB(tenantID string) *gorm.DB
- func (e *Application) GetTenantDBs(fn func(tenantID string, db *gorm.DB) bool)
- func (e *Application) GetTenantID(host string) string
- func (e *Application) GetTenantQueryDB(tenantID string) *gorm.DB
- func (e *Application) GetTenantQueryDBs(fn func(tenantID string, db *gorm.DB) bool)
- func (e *Application) SetAppRouters(appRouters func())
- func (e *Application) SetCacheAdapter(c storage.AdapterCache)
- func (e *Application) SetConfig(key string, value interface{})
- func (e *Application) SetEngine(engine http.Handler)
- func (e *Application) SetEventBus(eb eventbus.EventBus)
- func (e *Application) SetHandler(key string, routerGroup func(r *gin.RouterGroup, hand ...*gin.HandlerFunc))
- func (e *Application) SetLockerAdapter(c storage.AdapterLocker)
- func (e *Application) SetLogger(l *zap.Logger)
- func (e *Application) SetMiddleware(key string, middleware interface{})
- func (e *Application) SetQueueAdapter(c storage.AdapterQueue)
- func (e *Application) SetTenantCasbin(tenantID string, enforcer *casbin.SyncedEnforcer)
- func (e *Application) SetTenantCommandDB(tenantID string, db *gorm.DB)
- func (e *Application) SetTenantCrontab(tenantID string, crontab *cron.Cron)
- func (e *Application) SetTenantDB(tenantID string, db *gorm.DB)
- func (e *Application) SetTenantMapping(host, tenantID string)
- func (e *Application) SetTenantQueryDB(tenantID string, db *gorm.DB)
- type Cache
- func (e Cache) Connect() error
- func (e Cache) Decrease(key string) error
- func (e Cache) Del(key string) error
- func (e Cache) Expire(key string, dur time.Duration) error
- func (e Cache) Get(key string) (string, error)
- func (e Cache) HashDel(hk, key string) error
- func (e Cache) HashGet(hk, key string) (string, error)
- func (e Cache) Increase(key string) error
- func (e Cache) PutToken(token *oauth2.Token) error
- func (e Cache) Set(key string, val interface{}, expire int) error
- func (e *Cache) SetPrefix(prefix string)
- func (e *Cache) String() string
- func (e Cache) Token() (token *oauth2.Token, err error)
- type Locker
- type Queue
- type Router
- type Routers
- type Runtime
- type TenantResolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewCache ¶
func NewCache(prefix string, store storage.AdapterCache, wxTokenStoreKey string) storage.AdapterCache
NewCache 创建对应上下文缓存
func NewLocker ¶
func NewLocker(prefix string, locker storage.AdapterLocker) storage.AdapterLocker
NewLocker 创建对应上下文分布式锁
func NewQueue ¶
func NewQueue(prefix string, queue storage.AdapterQueue) storage.AdapterQueue
NewQueue 创建对应上下文队列
Types ¶
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
func (*Application) GetAppRouters ¶
func (e *Application) GetAppRouters() []func()
GetAppRouters 获取app的路由
func (*Application) GetCacheAdapter ¶
func (e *Application) GetCacheAdapter() storage.AdapterCache
GetCacheAdapter 获取缓存
func (*Application) GetCachePrefix ¶
func (e *Application) GetCachePrefix(key string) storage.AdapterCache
GetCachePrefix 获取带租户标记的cache
func (*Application) GetCasbins ¶ added in v1.1.17
func (e *Application) GetCasbins(fn func(tenantID string, enforcer *casbin.SyncedEnforcer) bool)
GetCasbins 遍历所有租户casbin
func (*Application) GetConfig ¶
func (e *Application) GetConfig(key string) interface{}
GetConfig 获取对应key的config
func (*Application) GetCrontabs ¶ added in v1.1.17
func (e *Application) GetCrontabs(fn func(tenantID string, crontab *cron.Cron) bool)
GetCrontab 获取所有map里的crontab数据
func (*Application) GetEventBus ¶ added in v1.1.19
func (e *Application) GetEventBus() eventbus.EventBus
GetEventBus 获取事件总线
func (*Application) GetHandler ¶
func (e *Application) GetHandler() map[string][]func(r *gin.RouterGroup, hand ...*gin.HandlerFunc)
func (*Application) GetHandlerPrefix ¶
func (e *Application) GetHandlerPrefix(key string) []func(r *gin.RouterGroup, hand ...*gin.HandlerFunc)
func (*Application) GetLockerAdapter ¶
func (e *Application) GetLockerAdapter() storage.AdapterLocker
GetLockerAdapter 获取分布式锁
func (*Application) GetLockerPrefix ¶
func (e *Application) GetLockerPrefix(key string) storage.AdapterLocker
func (*Application) GetMemoryQueue ¶
func (e *Application) GetMemoryQueue(prefix string) storage.AdapterQueue
func (*Application) GetMiddleware ¶
func (e *Application) GetMiddleware() map[string]interface{}
GetMiddleware 获取所有中间件
func (*Application) GetMiddlewareKey ¶
func (e *Application) GetMiddlewareKey(key string) interface{}
GetMiddlewareKey 获取对应key的中间件
func (*Application) GetQueueAdapter ¶
func (e *Application) GetQueueAdapter() storage.AdapterQueue
GetQueueAdapter 获取队列适配器
func (*Application) GetQueuePrefix ¶
func (e *Application) GetQueuePrefix(key string) storage.AdapterQueue
GetQueuePrefix 获取带租户标记的queue
func (*Application) GetStreamMessage ¶
func (e *Application) GetStreamMessage(id, stream string, value map[string]interface{}) (storage.Messager, error)
GetStreamMessage 获取队列需要用的message
func (*Application) GetTenantCasbin ¶ added in v1.1.17
func (e *Application) GetTenantCasbin(tenantID string) *casbin.SyncedEnforcer
GetTenantCasbin 根据租户id获取casbin
func (*Application) GetTenantCommandDB ¶ added in v1.1.11
func (e *Application) GetTenantCommandDB(tenantID string) *gorm.DB
GetTenantCommandDB CQRS时,根据租户id获取CommandDB
func (*Application) GetTenantCommandDBs ¶ added in v1.1.11
func (e *Application) GetTenantCommandDBs(fn func(tenantID string, db *gorm.DB) bool)
GetTenantCommandDBs 遍历所有租户命令数据库连接
func (*Application) GetTenantCrontab ¶ added in v1.1.17
func (e *Application) GetTenantCrontab(tenantID string) *cron.Cron
GetCrontabKey 根据key获取crontab
func (*Application) GetTenantDB ¶ added in v1.1.11
func (e *Application) GetTenantDB(tenantID string) *gorm.DB
GetTenantDB 非CQRS时,根据租户id获取db
func (*Application) GetTenantDBs ¶ added in v1.1.11
func (e *Application) GetTenantDBs(fn func(tenantID string, db *gorm.DB) bool)
GetTenantDBs 遍历所有租户数据库连接 使用举例,统计活跃的数据库连接数 count := 0
app.GetTenantDBs(func(tenantID string, db *gorm.DB) bool {
if db != nil {
count++
}
return true
})
fmt.Printf("活跃租户数量: %d\n", count)
func (*Application) GetTenantID ¶ added in v1.1.11
func (e *Application) GetTenantID(host string) string
GetTenantID 获取租户id
func (*Application) GetTenantQueryDB ¶ added in v1.1.11
func (e *Application) GetTenantQueryDB(tenantID string) *gorm.DB
GetTenantQueryDB CQRS时,根据租户id获取QueryDB
func (*Application) GetTenantQueryDBs ¶ added in v1.1.11
func (e *Application) GetTenantQueryDBs(fn func(tenantID string, db *gorm.DB) bool)
GetTenantQueryDBs 遍历所有租户查询数据库连接
func (*Application) SetAppRouters ¶
func (e *Application) SetAppRouters(appRouters func())
SetAppRouters 设置app的路由
func (*Application) SetCacheAdapter ¶
func (e *Application) SetCacheAdapter(c storage.AdapterCache)
SetCacheAdapter 设置缓存
func (*Application) SetConfig ¶
func (e *Application) SetConfig(key string, value interface{})
SetConfig 设置对应key的config
func (*Application) SetEngine ¶
func (e *Application) SetEngine(engine http.Handler)
SetEngine 设置路由引擎
func (*Application) SetEventBus ¶ added in v1.1.19
func (e *Application) SetEventBus(eb eventbus.EventBus)
SetEventBus 设置事件总线
func (*Application) SetHandler ¶
func (e *Application) SetHandler(key string, routerGroup func(r *gin.RouterGroup, hand ...*gin.HandlerFunc))
func (*Application) SetLockerAdapter ¶
func (e *Application) SetLockerAdapter(c storage.AdapterLocker)
SetLockerAdapter 设置分布式锁
func (*Application) SetMiddleware ¶
func (e *Application) SetMiddleware(key string, middleware interface{})
SetMiddleware 设置中间件
func (*Application) SetQueueAdapter ¶
func (e *Application) SetQueueAdapter(c storage.AdapterQueue)
SetQueueAdapter 设置队列适配器
func (*Application) SetTenantCasbin ¶ added in v1.1.17
func (e *Application) SetTenantCasbin(tenantID string, enforcer *casbin.SyncedEnforcer)
SetTenantCasbin 设置对应租户的casbin
func (*Application) SetTenantCommandDB ¶ added in v1.1.11
func (e *Application) SetTenantCommandDB(tenantID string, db *gorm.DB)
SetTenantCommandDB CQRS时,设置租户的CommandDB
func (*Application) SetTenantCrontab ¶ added in v1.1.17
func (e *Application) SetTenantCrontab(tenantID string, crontab *cron.Cron)
SetCrontab 设置对应key的crontab
func (*Application) SetTenantDB ¶ added in v1.1.11
func (e *Application) SetTenantDB(tenantID string, db *gorm.DB)
SetTenantDB 非CQRS时,设置租户数据库连接
func (*Application) SetTenantMapping ¶ added in v1.1.11
func (e *Application) SetTenantMapping(host, tenantID string)
SetTenantMapping 添加或更新域名到租户ID的映射
func (*Application) SetTenantQueryDB ¶ added in v1.1.11
func (e *Application) SetTenantQueryDB(tenantID string, db *gorm.DB)
SetTenantQueryDB CQRS时,设置租户的QueryDB
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
type Locker ¶
type Locker struct {
// contains filtered or unexported fields
}
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
type Runtime ¶
type Runtime interface {
// GetTenantID 获取租户id
SetTenantMapping(host, tenantID string)
GetTenantID(host string) string
// SetDb 非CQRS时,多db设置,⚠️SetDbs不允许并发,可以根据自己的业务,例如app分库(用分表分库,或不同微服务实现)、host分库(多租户)
SetTenantDB(tenantID string, db *gorm.DB)
GetTenantDB(tenantID string) *gorm.DB
GetTenantDBs(fn func(tenantID string, db *gorm.DB) bool)
// SetTenantCommandDB CQRS时,设置对应租户的Command db
SetTenantCommandDB(tenantID string, db *gorm.DB)
GetTenantCommandDB(tenantID string) *gorm.DB
GetTenantCommandDBs(fn func(tenantID string, db *gorm.DB) bool)
// SetTenantQueryDB CQRS时,设置对应租户的Query db
SetTenantQueryDB(tenantID string, db *gorm.DB)
GetTenantQueryDB(tenantID string) *gorm.DB
GetTenantQueryDBs(fn func(tenantID string, db *gorm.DB) bool)
// SetTenantCasbin 设置对应租户的casbin
SetTenantCasbin(tenantID string, enforcer *casbin.SyncedEnforcer)
// GetTenantCasbin 根据租户id获取casbin
GetTenantCasbin(tenantID string) *casbin.SyncedEnforcer
// GetCasbins 获取所有casbin
GetCasbins(fn func(tenantID string, enforcer *casbin.SyncedEnforcer) bool)
// SetEngine 使用的路由
SetEngine(engine http.Handler)
GetEngine() http.Handler
GetRouter() []Router
// SetLogger 使用zap
SetLogger(logger *zap.Logger)
GetLogger() *zap.Logger
// SetCrontab crontab
SetTenantCrontab(tenantID string, crontab *cron.Cron)
GetTenantCrontab(tenantID string) *cron.Cron
GetCrontabs(fn func(tenantID string, crontab *cron.Cron) bool)
// SetMiddleware middleware
SetMiddleware(string, interface{})
GetMiddleware() map[string]interface{}
GetMiddlewareKey(key string) interface{}
// SetCacheAdapter cache
SetCacheAdapter(storage.AdapterCache)
GetCacheAdapter() storage.AdapterCache
GetCachePrefix(string) storage.AdapterCache
GetMemoryQueue(string) storage.AdapterQueue
SetQueueAdapter(storage.AdapterQueue)
GetQueueAdapter() storage.AdapterQueue
GetQueuePrefix(string) storage.AdapterQueue
SetLockerAdapter(storage.AdapterLocker)
GetLockerAdapter() storage.AdapterLocker
GetLockerPrefix(string) storage.AdapterLocker
SetHandler(key string, routerGroup func(r *gin.RouterGroup, hand ...*gin.HandlerFunc))
GetHandler() map[string][]func(r *gin.RouterGroup, hand ...*gin.HandlerFunc)
GetHandlerPrefix(key string) []func(r *gin.RouterGroup, hand ...*gin.HandlerFunc)
GetStreamMessage(id, stream string, value map[string]interface{}) (storage.Messager, error)
GetConfig(key string) interface{}
SetConfig(key string, value interface{})
// SetAppRouters set AppRouter
SetAppRouters(appRouters func())
GetAppRouters() []func()
// SetEventBus 设置事件总线
SetEventBus(eventbus.EventBus)
// GetEventBus 获取事件总线
GetEventBus() eventbus.EventBus
}
type TenantResolver ¶ added in v1.1.11
type TenantResolver struct {
// contains filtered or unexported fields
}
TenantResolver 使用 sync.Map 实现高并发租户解析
func NewTenantResolver ¶ added in v1.1.11
func NewTenantResolver() *TenantResolver
NewTenantResolver 创建一个新的租户解析器
func (*TenantResolver) GetTenantID ¶ added in v1.1.11
func (tr *TenantResolver) GetTenantID(host string) (string, bool)
GetTenantID 通过主机名获取租户ID
func (*TenantResolver) LoadFromMap ¶ added in v1.1.11
func (tr *TenantResolver) LoadFromMap(mappings map[string]string)
LoadFromMap 批量加载映射数据
func (*TenantResolver) SetTenantMapping ¶ added in v1.1.11
func (tr *TenantResolver) SetTenantMapping(host, tenantID string)
SetTenantMapping 添加或更新域名到租户ID的映射