Documentation
¶
Index ¶
- Constants
- func NewCache(prefix string, store storage.AdapterCache, wxTokenStoreKey string) storage.AdapterCache
- func NewQueue(prefix string, q storage.AdapterQueue) storage.AdapterQueue
- type Application
- func (e *Application) AppRoutersSealed() bool
- func (e *Application) BeforeSealed() bool
- func (e *Application) GetAllCasbin() map[string]*casbin.SyncedEnforcer
- func (e *Application) GetAllCrontab() map[string]*cron.Cron
- func (e *Application) GetAllDb() map[string]*gorm.DB
- func (e *Application) GetAllHandler() map[string][]func(r *gin.RouterGroup, hand ...*gin.HandlerFunc)
- func (e *Application) GetAllMiddleware() map[string]interface{}
- func (e *Application) GetApp() map[string]interface{}
- func (e *Application) GetAppByTenant(tenant string) interface{}
- func (e *Application) GetAppRouters() []func()deprecated
- func (e *Application) GetBefore() []func()deprecated
- func (e *Application) GetCacheAdapter() storage.AdapterCache
- func (e *Application) GetCacheAdapterPrefix(prefix string) storage.AdapterCache
- func (e *Application) GetCasbin() *casbin.SyncedEnforcer
- func (e *Application) GetCasbinByTenant(tenant string) *casbin.SyncedEnforcer
- func (e *Application) GetCasbinExclude() map[string]interface{}
- func (e *Application) GetCasbinExcludeByTenant(tenant string) interface{}
- func (e *Application) GetConfig() map[string]interface{}
- func (e *Application) GetConfigByTenant(tenant string) map[string]interface{}
- func (e *Application) GetConfigValue(key string) interface{}
- func (e *Application) GetConfigValueByTenant(tenant, key string) interface{}
- func (e *Application) GetCrontab() *cron.Cron
- func (e *Application) GetCrontabByTenant(tenant string) *cron.Cron
- func (e *Application) GetDb() *gorm.DB
- func (e *Application) GetDbByTenant(tenant string) *gorm.DB
- func (e *Application) GetDefaultTenant() string
- func (e *Application) GetEngine() http.Handler
- func (e *Application) GetHandler() []func(r *gin.RouterGroup, hand ...*gin.HandlerFunc)
- func (e *Application) GetHandlerByTenant(tenant string) []func(r *gin.RouterGroup, hand ...*gin.HandlerFunc)
- func (e *Application) GetLogger() logger.Logger
- func (e *Application) GetMemoryQueue(prefix string) storage.AdapterQueuedeprecated
- func (e *Application) GetMiddleware(key string) interface{}
- func (e *Application) GetQueue() storage.AdapterQueue
- 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) RunAppRouters()
- func (e *Application) RunBefore()
- func (e *Application) SetApp(app interface{})
- func (e *Application) SetAppByTenant(key string, app interface{})
- func (e *Application) SetAppRouters(appRouters func())
- func (e *Application) SetAppRoutersWith(appRouters func(), opts ...CallbackOption)
- func (e *Application) SetBefore(f func())
- func (e *Application) SetBeforeWith(f func(), opts ...CallbackOption)
- func (e *Application) SetCacheAdapter(c storage.AdapterCache)
- func (e *Application) SetCasbin(enforcer *casbin.SyncedEnforcer)
- func (e *Application) SetCasbinByTenant(tenant string, enforcer *casbin.SyncedEnforcer)
- func (e *Application) SetCasbinExclude(list interface{})
- func (e *Application) SetCasbinExcludeByTenant(tenant string, list interface{})
- func (e *Application) SetConfigByTenant(tenant string, value map[string]interface{})
- func (e *Application) SetConfigValue(key string, value interface{})
- func (e *Application) SetConfigValueByTenant(tenant, key string, value interface{})
- func (e *Application) SetCrontab(crontab *cron.Cron)
- func (e *Application) SetCrontabByTenant(key string, crontab *cron.Cron)
- func (e *Application) SetDb(db *gorm.DB)
- func (e *Application) SetDbByTenant(tenant string, db *gorm.DB)
- func (e *Application) SetDefaultTenant(tenant string)
- func (e *Application) SetEngine(engine http.Handler)
- func (e *Application) SetHandler(routerGroup func(r *gin.RouterGroup, hand ...*gin.HandlerFunc))
- func (e *Application) SetHandlerByTenant(tenant string, routerGroup func(r *gin.RouterGroup, hand ...*gin.HandlerFunc))
- func (e *Application) SetLogger(l logger.Logger)
- func (e *Application) SetMiddleware(key string, middleware interface{})
- func (e *Application) SetQueueAdapter(c storage.AdapterQueue)
- 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 CallbackOption
- type Config
- type Queue
- type Router
- type Routers
- type Runtime
Constants ¶
const DefaultTenant = "default"
DefaultTenant 默认租户标识符
Variables ¶
This section is empty.
Functions ¶
func NewCache ¶
func NewCache(prefix string, store storage.AdapterCache, wxTokenStoreKey string) storage.AdapterCache
NewCache 创建对应上下文缓存
func NewQueue ¶
func NewQueue(prefix string, q storage.AdapterQueue) storage.AdapterQueue
NewQueue 创建对应上下文队列
A nil q yields a fresh in-process queue, which is almost never what a caller wants: it works, but it is private to the returned handle, so a consumer registered through one call never sees what another publishes. Application.GetQueuePrefix passes a shared queue for exactly this reason.
Types ¶
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
func (*Application) AppRoutersSealed ¶ added in v2.4.0
func (e *Application) AppRoutersSealed() bool
AppRoutersSealed reports whether RunAppRouters has run. A registration made after that point is dropped, so an installer can ask rather than find out from a log line.
func (*Application) BeforeSealed ¶ added in v2.4.0
func (e *Application) BeforeSealed() bool
BeforeSealed reports whether RunBefore has run. A registration made after that point is dropped, so an installer can ask rather than find out from a log line.
func (*Application) GetAllCasbin ¶
func (e *Application) GetAllCasbin() map[string]*casbin.SyncedEnforcer
GetAllCasbin 获取所有租户的casbin (原GetCasbin改名)
func (*Application) GetAllCrontab ¶
func (e *Application) GetAllCrontab() map[string]*cron.Cron
GetAllCrontab 获取所有租户的定时任务 (原GetCrontab改名)
func (*Application) GetAllDb ¶
func (e *Application) GetAllDb() map[string]*gorm.DB
GetAllDb 获取所有租户的数据库 (原GetDb改名) GetAllDb returns a snapshot. Handing back the map itself was a race the lock could not fix: it was held across the return and released before the caller read anything.
func (*Application) GetAllHandler ¶
func (e *Application) GetAllHandler() map[string][]func(r *gin.RouterGroup, hand ...*gin.HandlerFunc)
func (*Application) GetAllMiddleware ¶
func (e *Application) GetAllMiddleware() map[string]interface{}
GetAllMiddleware 获取所有中间件
func (*Application) GetApp ¶
func (e *Application) GetApp() map[string]interface{}
GetApp 获取所有map里的app数据
func (*Application) GetAppByTenant ¶
func (e *Application) GetAppByTenant(tenant string) interface{}
GetAppByTenant 根据key获取app
func (*Application) GetAppRouters
deprecated
func (e *Application) GetAppRouters() []func()
GetAppRouters returns the registered router initialisers, in registration order.
Deprecated: use RunAppRouters. Running the returned callbacks yourself gets no panic guard and no failure levels, and core cannot see your loop: calling RunAppRouters afterwards runs everything a second time.
func (*Application) GetBefore
deprecated
func (e *Application) GetBefore() []func()
GetBefore returns the registered before callbacks, in registration order.
Deprecated: use RunBefore. Running the returned callbacks yourself gets no panic guard and no failure levels, and core cannot see your loop: calling RunBefore afterwards runs everything a second time.
func (*Application) GetCacheAdapter ¶
func (e *Application) GetCacheAdapter() storage.AdapterCache
GetCacheAdapter 获取缓存
func (*Application) GetCacheAdapterPrefix ¶
func (e *Application) GetCacheAdapterPrefix(prefix string) storage.AdapterCache
GetCacheAdapterPrefix 获取prefix标记的cache
func (*Application) GetCasbin ¶
func (e *Application) GetCasbin() *casbin.SyncedEnforcer
GetCasbin 获取默认租户的casbin (新增单租户快捷方法)
func (*Application) GetCasbinByTenant ¶
func (e *Application) GetCasbinByTenant(tenant string) *casbin.SyncedEnforcer
GetCasbinByTenant 根据租户获取casbin
func (*Application) GetCasbinExclude ¶
func (e *Application) GetCasbinExclude() map[string]interface{}
GetCasbinExclude 获取所有map里的Exclude数据
func (*Application) GetCasbinExcludeByTenant ¶
func (e *Application) GetCasbinExcludeByTenant(tenant string) interface{}
GetCasbinExcludeByTenant 根据租户获取Exclude
func (*Application) GetConfig ¶
func (e *Application) GetConfig() map[string]interface{}
GetConfig 获取默认租户的config
func (*Application) GetConfigByTenant ¶
func (e *Application) GetConfigByTenant(tenant string) map[string]interface{}
GetConfigByTenant 获取对应租户的config
func (*Application) GetConfigValue ¶
func (e *Application) GetConfigValue(key string) interface{}
GetConfigValue 获取默认租户的配置值
func (*Application) GetConfigValueByTenant ¶
func (e *Application) GetConfigValueByTenant(tenant, key string) interface{}
GetConfigValueByTenant 获取对应租户的config
func (*Application) GetCrontab ¶
func (e *Application) GetCrontab() *cron.Cron
GetCrontab 获取默认租户的定时任务 (新增单租户快捷方法)
func (*Application) GetCrontabByTenant ¶
func (e *Application) GetCrontabByTenant(tenant string) *cron.Cron
GetCrontabByTenant 根据租户获取crontab
func (*Application) GetDbByTenant ¶
func (e *Application) GetDbByTenant(tenant string) *gorm.DB
GetDbByTenant 根据租户获取db
func (*Application) GetDefaultTenant ¶
func (e *Application) GetDefaultTenant() string
GetDefaultTenant 获取默认租户
func (*Application) GetHandler ¶
func (e *Application) GetHandler() []func(r *gin.RouterGroup, hand ...*gin.HandlerFunc)
func (*Application) GetHandlerByTenant ¶
func (e *Application) GetHandlerByTenant(tenant string) []func(r *gin.RouterGroup, hand ...*gin.HandlerFunc)
func (*Application) GetMemoryQueue
deprecated
func (e *Application) GetMemoryQueue(prefix string) storage.AdapterQueue
GetMemoryQueue returns the in-process queue.
Deprecated: use GetQueuePrefix. This always returns the in-process queue, whatever the configuration selected, so messages published through it are invisible to every other instance.
func (*Application) GetMiddleware ¶
func (e *Application) GetMiddleware(key string) interface{}
GetMiddleware 获取对应的中间件
func (*Application) GetQueue ¶
func (e *Application) GetQueue() storage.AdapterQueue
GetQueue 获取默认租户的队列
func (*Application) GetQueueAdapter ¶
func (e *Application) GetQueueAdapter() storage.AdapterQueue
GetQueueAdapter 获取队列适配器
func (*Application) GetQueuePrefix ¶
func (e *Application) GetQueuePrefix(key string) storage.AdapterQueue
GetQueuePrefix 获取标记的queue
This is the queue the configuration selected. Prefer it over GetMemoryQueue, which ignores configuration and never leaves the process.
func (*Application) GetStreamMessage ¶
func (e *Application) GetStreamMessage(id, stream string, value map[string]interface{}) (storage.Messager, error)
GetStreamMessage 获取队列需要用的message
func (*Application) RunAppRouters ¶ added in v2.4.0
func (e *Application) RunAppRouters()
RunAppRouters executes every router initialiser that has not run yet, in registration order, and closes the registry to further registration.
Calling it again is a no-op: the initialisers that already ran do not run twice.
func (*Application) RunBefore ¶ added in v2.4.0
func (e *Application) RunBefore()
RunBefore executes every before callback that has not run yet, in registration order, and closes the registry to further registration.
Calling it again is a no-op: the callbacks that already ran do not run twice.
func (*Application) SetAppByTenant ¶
func (e *Application) SetAppByTenant(key string, app interface{})
SetAppByTenant 设置对应租户的app
func (*Application) SetAppRouters ¶
func (e *Application) SetAppRouters(appRouters func())
SetAppRouters registers a router initialiser for an application module.
The callback runs when RunAppRouters is called, in registration order, behind a panic guard. Registering after RunAppRouters has run is refused and reported.
func (*Application) SetAppRoutersWith ¶ added in v2.4.0
func (e *Application) SetAppRoutersWith(appRouters func(), opts ...CallbackOption)
SetAppRoutersWith registers a router initialiser and configures how a panic in it is treated. With no options it is identical to SetAppRouters.
func (*Application) SetBefore ¶
func (e *Application) SetBefore(f func())
SetBefore registers a callback to run before the server starts.
The callback runs when RunBefore is called, in registration order, behind a panic guard. Registering after RunBefore has run is refused and reported.
func (*Application) SetBeforeWith ¶ added in v2.4.0
func (e *Application) SetBeforeWith(f func(), opts ...CallbackOption)
SetBeforeWith registers a before callback and configures how a panic in it is treated. With no options it is identical to SetBefore.
func (*Application) SetCacheAdapter ¶
func (e *Application) SetCacheAdapter(c storage.AdapterCache)
SetCacheAdapter 设置缓存
func (*Application) SetCasbin ¶
func (e *Application) SetCasbin(enforcer *casbin.SyncedEnforcer)
SetCasbin 设置默认租户的casbin
func (*Application) SetCasbinByTenant ¶
func (e *Application) SetCasbinByTenant(tenant string, enforcer *casbin.SyncedEnforcer)
func (*Application) SetCasbinExclude ¶
func (e *Application) SetCasbinExclude(list interface{})
SetCasbinExclude 设置默认租户的Exclude
func (*Application) SetCasbinExcludeByTenant ¶
func (e *Application) SetCasbinExcludeByTenant(tenant string, list interface{})
SetCasbinExcludeByTenant 设置对应租户的Exclude
func (*Application) SetConfigByTenant ¶
func (e *Application) SetConfigByTenant(tenant string, value map[string]interface{})
SetConfigByTenant 设置对应租户的config
func (*Application) SetConfigValue ¶
func (e *Application) SetConfigValue(key string, value interface{})
SetConfigValue 设置默认租户的配置值
func (*Application) SetConfigValueByTenant ¶
func (e *Application) SetConfigValueByTenant(tenant, key string, value interface{})
SetConfigValueByTenant 设置对应租户的key的config
func (*Application) SetCrontab ¶
func (e *Application) SetCrontab(crontab *cron.Cron)
SetCrontab 设置默认租户的crontab
func (*Application) SetCrontabByTenant ¶
func (e *Application) SetCrontabByTenant(key string, crontab *cron.Cron)
SetCrontabByTenant 设置对应租户的crontab
func (*Application) SetDbByTenant ¶
func (e *Application) SetDbByTenant(tenant string, db *gorm.DB)
SetDbByTenant 设置对应租户的db
func (*Application) SetDefaultTenant ¶
func (e *Application) SetDefaultTenant(tenant string)
SetDefaultTenant 设置默认租户
func (*Application) SetEngine ¶
func (e *Application) SetEngine(engine http.Handler)
SetEngine 设置路由引擎
An app router callback is allowed to call this - the demo module does, on the path where no engine has been set yet - so the field is written after the server has started reading it elsewhere, and needs the lock.
func (*Application) SetHandler ¶
func (e *Application) SetHandler(routerGroup func(r *gin.RouterGroup, hand ...*gin.HandlerFunc))
func (*Application) SetHandlerByTenant ¶
func (e *Application) SetHandlerByTenant(tenant string, routerGroup func(r *gin.RouterGroup, hand ...*gin.HandlerFunc))
func (*Application) SetMiddleware ¶
func (e *Application) SetMiddleware(key string, middleware interface{})
SetMiddleware 设置租户中间件
func (*Application) SetQueueAdapter ¶
func (e *Application) SetQueueAdapter(c storage.AdapterQueue)
SetQueueAdapter 设置队列适配器
Reloading the configuration calls this again while requests are in flight, so the field is guarded.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
type CallbackOption ¶ added in v2.4.0
type CallbackOption func(*callbackConfig)
CallbackOption configures a callback registered through SetBeforeWith or SetAppRoutersWith.
Passing no options is the historical behaviour: a panic is logged and the remaining callbacks still run. Nothing a caller does not ask for changes.
func WithFatal ¶ added in v2.4.0
func WithFatal() CallbackOption
WithFatal marks a callback the process must not start without: a panic in it is logged and then the process exits with status 1.
This is the exception, not the default. An application that marks itself fatal makes the whole host program as fragile as itself, and the exit skips every deferred cleanup - so it only belongs on work that happens before the server starts listening.
func WithName ¶ added in v2.4.0
func WithName(name string) CallbackOption
WithName labels the callback in guard logs. Without it the log carries the registration site only, which is enough to find the code but not enough to know what it was for.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
type Runtime ¶
type Runtime interface {
// SetDbByTenant 设置租户数据库
SetDbByTenant(tenant string, db *gorm.DB)
// SetDb 设置默认租户数据库
SetDb(db *gorm.DB)
GetDbByTenant(tenant string) *gorm.DB
GetDb() *gorm.DB
GetAllDb() map[string]*gorm.DB
// SetBefore registers a callback to run when RunBefore is called.
SetBefore(f func())
// SetBeforeWith registers a before callback and says how a panic in it is
// treated. With no options it is identical to SetBefore.
SetBeforeWith(f func(), opts ...CallbackOption)
// GetBefore returns the registered before callbacks.
//
// Deprecated: use RunBefore.
GetBefore() []func()
// RunBefore executes the before callbacks that have not run yet, in
// registration order, and closes the registry.
RunBefore()
// BeforeSealed reports whether RunBefore has run, i.e. whether a further
// SetBefore would be dropped.
BeforeSealed() bool
SetAppByTenant(tenant string, app interface{})
SetApp(app interface{})
GetApp() map[string]interface{}
GetAppByTenant(tenant string) interface{}
SetCasbinExcludeByTenant(tenant string, list interface{})
SetCasbinExclude(list interface{})
GetCasbinExclude() map[string]interface{}
GetCasbinExcludeByTenant(tenant string) interface{}
SetCasbinByTenant(tenant string, enforcer *casbin.SyncedEnforcer)
SetCasbin(enforcer *casbin.SyncedEnforcer)
GetAllCasbin() map[string]*casbin.SyncedEnforcer
GetCasbin() *casbin.SyncedEnforcer
GetCasbinByTenant(tenant string) *casbin.SyncedEnforcer
// SetEngine 使用的路由
SetEngine(engine http.Handler)
GetEngine() http.Handler
GetRouter() []Router
// SetLogger 使用go-admin定义的logger,参考来源go-micro
SetLogger(logger logger.Logger)
GetLogger() logger.Logger
SetDefaultTenant(tenant string)
GetDefaultTenant() string
// SetCrontabByTenant crontab
SetCrontabByTenant(tenant string, crontab *cron.Cron)
SetCrontab(crontab *cron.Cron)
GetCrontab() *cron.Cron
GetAllCrontab() map[string]*cron.Cron
GetCrontabByTenant(tenant string) *cron.Cron
// SetMiddleware middleware
SetMiddleware(string, interface{})
GetAllMiddleware() map[string]interface{}
GetMiddleware(string) interface{}
// SetCacheAdapter cache
SetCacheAdapter(storage.AdapterCache)
GetCacheAdapter() storage.AdapterCache
GetCacheAdapterPrefix(string) storage.AdapterCache
GetMemoryQueue(string) storage.AdapterQueue
SetQueueAdapter(storage.AdapterQueue)
GetQueueAdapter() storage.AdapterQueue
GetQueuePrefix(string) storage.AdapterQueue
SetHandler(routerGroup func(r *gin.RouterGroup, hand ...*gin.HandlerFunc))
SetHandlerByTenant(tenant string, routerGroup func(r *gin.RouterGroup, hand ...*gin.HandlerFunc))
GetAllHandler() map[string][]func(r *gin.RouterGroup, hand ...*gin.HandlerFunc)
GetHandler() []func(r *gin.RouterGroup, hand ...*gin.HandlerFunc)
GetHandlerByTenant(tenant string) []func(r *gin.RouterGroup, hand ...*gin.HandlerFunc)
GetStreamMessage(id, stream string, value map[string]interface{}) (storage.Messager, error)
// SetConfigByTenant 设置对应租户的config
SetConfigByTenant(tenant string, value map[string]interface{})
// SetConfigValueByTenant 设置对应租户的key对应的value
SetConfigValueByTenant(tenant, key string, value interface{})
SetConfigValue(key string, value interface{})
GetConfigValueByTenant(tenant, key string) interface{}
GetConfigByTenant(tenant string) map[string]interface{}
GetConfig() map[string]interface{}
GetConfigValue(key string) interface{}
// SetAppRouters registers a router initialiser to run when RunAppRouters
// is called.
SetAppRouters(appRouters func())
// SetAppRoutersWith registers a router initialiser and says how a panic in
// it is treated. With no options it is identical to SetAppRouters.
SetAppRoutersWith(appRouters func(), opts ...CallbackOption)
// GetAppRouters returns the registered router initialisers.
//
// Deprecated: use RunAppRouters.
GetAppRouters() []func()
// RunAppRouters executes the router initialisers that have not run yet, in
// registration order, and closes the registry.
RunAppRouters()
// AppRoutersSealed reports whether RunAppRouters has run, i.e. whether a
// further SetAppRouters would be dropped.
AppRoutersSealed() bool
}