runtime

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JwtTokenCheck   = "JwtToken"
	RoleCheck       = "AuthCheckRole"
	PermissionCheck = "PermissionAction"
)

Well-known keys the host registers under with SetMiddleware. An application that wants to reuse the host's own authentication and authorization chain - rather than build its own - looks these up through GetHandlerFunc instead of importing the host package that built them.

All three keys are expected to store a gin.HandlerFunc. That is a change from an earlier host convention where the JWT key stored an unbound method expression: a value with no receiver bound to it, which a caller cannot turn into a working gin.HandlerFunc no matter how it type-asserts. Hosts must register a bound closure (for example authMiddleware.MiddlewareFunc(), not (*jwt.GinJWTMiddleware).MiddlewareFunc) so all three keys have the same shape and GetHandlerFunc works uniformly across them.

View Source
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 NewConfig

func NewConfig() *Application

NewConfig 默认值

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) BeginShutdown added in v2.6.0

func (e *Application) BeginShutdown()

BeginShutdown says that the application is on its way out, and closes the phases that only make sense on the way in.

It exists because the last configuration reload can outlive the decision to stop. Closing the config watcher does not wait for a reload already in flight, and that reload finishes by rebuilding the database, the cache and the queue and announcing them - which, in the middle of a shutdown, undoes the cleanup that has just run and starts consumers on a process that is being taken apart. AfterResource is also the one phase that never closes, so without this there is nothing to stop code registering into it while the process is going down.

After this call SetPhase and RunPhase do nothing for every phase but BeforeExit, and say so. BeforeExit keeps working: it is the phase this call is on the way to. There is no way back - a process does not un-shut-down - and calling it twice is harmless.

It does not interrupt a phase already running. It closes the door; it does not reach into the room.

RunShutdown calls it, so a host that only calls RunShutdown is covered from that moment on. Calling it as the first step of the shutdown path is what covers the window before then, which is the wider one: it spans the whole of the HTTP server's own graceful shutdown.

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

func (e *Application) GetDb() *gorm.DB

GetDb 获取默认租户的数据库 (新增单租户快捷方法)

func (*Application) GetDbByTenant

func (e *Application) GetDbByTenant(tenant string) *gorm.DB

GetDbByTenant 根据租户获取db

func (*Application) GetDefaultTenant

func (e *Application) GetDefaultTenant() string

GetDefaultTenant 获取默认租户

func (*Application) GetEngine

func (e *Application) GetEngine() http.Handler

GetEngine 获取路由引擎

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) GetHandlerFunc added in v2.5.0

func (e *Application) GetHandlerFunc(key string) (gin.HandlerFunc, bool)

GetHandlerFunc is GetMiddleware plus the type assertion every caller of it otherwise has to repeat, and a reported failure instead of a panic when the key was never registered or was registered with something other than a gin.HandlerFunc.

The bool result exists because a bare type assertion turns two different, unrelated problems - "not registered yet" and "registered with the wrong shape" - into a panic at the call site, typically inside a router initialiser that runs behind this framework's panic guard (see docs/contract.md section 4), which then reports the module as having failed to register any routes at all rather than naming the real cause. Callers that need JWT enforcement to be non-optional should still check ok explicitly and fail loudly, since a missing middleware is not a state a router should silently continue past.

func (*Application) GetLogger

func (e *Application) GetLogger() logger.Logger

GetLogger 获取日志组件

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

func (e *Application) GetRouter() []Router

GetRouter 获取路由表

func (*Application) GetStreamMessage

func (e *Application) GetStreamMessage(id, stream string, value map[string]interface{}) (storage.Messager, error)

GetStreamMessage 获取队列需要用的message

func (*Application) PhaseSealed added in v2.6.0

func (e *Application) PhaseSealed(p Phase) bool

PhaseSealed reports whether p has already run, i.e. whether a further SetPhase for it would be dropped.

AfterResource always reports false: it is re-entrant, so registering into it is never too late - though a callback that arrives after the last reload of the process will not run until the next one.

A phase that is not one of the four constants reports true: "your callback will not run in that phase" is the answer that keeps a caller from registering into a hole, and it is also reported, because asking about a phase that does not exist is a mistake in the caller either way.

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) RunPhase added in v2.6.0

func (e *Application) RunPhase(p Phase)

RunPhase executes the callbacks registered for p, in registration order.

The callbacks run with no lock held, because they routinely call back into Application and sync.RWMutex is not reentrant. A p that is not one of the four constants is reported and does nothing.

For every phase but AfterResource this happens once: the phase is closed to further registration afterwards, and calling RunPhase again is a no-op, so cleanup registered in BeforeExit cannot run twice.

BeforeExit is the other exception, in the other direction: it runs in reverse registration order, because it is the phase that unwinds. See SetShutdown, which registers into the same phase and is how a callback that wants the remaining budget asks for it.

AfterResource is the exception, because the resources it announces are rebuilt on every configuration reload. It never closes, every registered callback runs again on every round, and a callback that arrives while a round is running is picked up by the next one. Two rounds never overlap: a trigger that arrives during a round records that another round is owed and returns without waiting for it, which makes RunPhase(AfterResource) the one case that can return before the work is done. See runReentrant.

func (*Application) RunShutdown added in v2.6.0

func (e *Application) RunShutdown(ctx context.Context) error

RunShutdown runs the BeforeExit callbacks, in reverse registration order, within the caller's context, and closes the phase.

It returns ctx.Err() if the context ends first, and nil otherwise. Calling it again runs nothing: cleanup that already ran does not run twice, because closing a connection pool twice is worse than not closing it.

What the context bounds is the wait, not the work. The callbacks run on their own goroutine; when the budget is gone this method stops waiting and returns, and the callback that is running carries on until the process exits - possibly leaving whatever it was writing half-written. There is no way to do better: Go cannot cancel a function that does not check for it, which is why the callbacks are handed a context in the first place. The callback holding things up is named in the log.

With nothing registered it returns nil immediately, without a goroutine and without consulting the context: nothing to run is not a timeout.

func (*Application) SetApp

func (e *Application) SetApp(app interface{})

SetApp 设置默认租户的app

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

func (e *Application) SetDb(db *gorm.DB)

SetDb 设置默认租户的db

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

func (e *Application) SetLogger(l logger.Logger)

SetLogger 设置日志组件

func (*Application) SetMiddleware

func (e *Application) SetMiddleware(key string, middleware interface{})

SetMiddleware 设置租户中间件

func (*Application) SetPhase added in v2.6.0

func (e *Application) SetPhase(p Phase, f func(), opts ...CallbackOption)

SetPhase registers a callback to run when the application reaches p.

The callback runs when RunPhase(p) is called, in registration order, behind the same panic guard as SetBefore: a panic is logged with the registration site and the remaining callbacks still run, unless WithFatal says otherwise.

Registering after that phase has already run is refused and reported, and so is a p that is not one of the four constants - neither panics, because an installer registering a hook is usually running inside an init() where a panic takes the whole program down and names this file rather than the caller. Ask PhaseSealed if you need to know rather than read it in a log.

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.

func (*Application) SetShutdown added in v2.6.0

func (e *Application) SetShutdown(f func(context.Context), opts ...CallbackOption)

SetShutdown registers a callback to run on the way out, once the server has stopped serving.

It is the context-taking half of SetPhase(BeforeExit, ...): both register into the same phase, and one pass runs both. The context carries whatever budget the host allowed for shutdown, so a callback that can cut its work short - drain for what is left rather than for a fixed time - has something to look at. One that cannot is free to ignore it.

The callbacks run in reverse registration order, which is the right default for a chain of hooks that built on each other: the last one registered is the one most likely to depend on the others. It says nothing about resources the host created for itself, which were not built by this chain and are not unwound by it.

WithFatal is not honoured here, and saying so is the point: exiting from inside cleanup skips every callback after it, which is the opposite of what the option is for. The callback is kept and the option is reported, because refusing the registration would mean one mistyped option costs you the cleanup entirely - silently.

type Cache

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

func (Cache) Connect

func (e Cache) Connect() error

Connect 初始化

func (Cache) Decrease

func (e Cache) Decrease(key string) error

func (Cache) Del

func (e Cache) Del(key string) error

Del delete key in cache

func (Cache) Expire

func (e Cache) Expire(key string, dur time.Duration) error

func (Cache) Get

func (e Cache) Get(key string) (string, error)

Get val in cache

func (Cache) HashDel

func (e Cache) HashDel(hk, key string) error

HashDel delete one key:value pair in hashtable cache

func (Cache) HashGet

func (e Cache) HashGet(hk, key string) (string, error)

HashGet get val in hashtable cache

func (Cache) Increase

func (e Cache) Increase(key string) error

Increase value

func (Cache) PutToken

func (e Cache) PutToken(token *oauth2.Token) error

PutToken 设置微信oauth2 token

func (Cache) Set

func (e Cache) Set(key string, val interface{}, expire int) error

Set val in cache

func (*Cache) SetPrefix

func (e *Cache) SetPrefix(prefix string)

SetPrefix 设置前缀

func (*Cache) String

func (e *Cache) String() string

String string输出

func (Cache) Token

func (e Cache) Token() (token *oauth2.Token, err error)

Token 获取微信oauth2 token

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 Config

type Config map[string]interface{}

type Phase added in v2.6.0

type Phase int

Phase names a point in the life of the application that a module can attach work to.

The values are assigned explicitly rather than with iota, and with gaps: a phase inserted later takes a number in a gap instead of moving the numbers already compiled into somebody else's binary, so p1 < p2 keeps meaning "p1 is reached first".

That orders the first pass and nothing else. AfterResource runs again on every configuration reload, so for the rest of the process's life it happens after AfterListen while still holding the smaller number: < cannot answer "has that phase already run". PhaseSealed can.

The numbers themselves are an implementation detail. They are not part of the contract, and must not be persisted, sent over the wire, or written into configuration - name the constant instead.

const (
	// AfterResource is reached once the database, cache, queue and casbin
	// enforcer have been built from the configuration that is current at that
	// moment.
	//
	// It is the one phase that runs more than once: a configuration reload
	// rebuilds those resources, and the point of the phase is to give the
	// code that depends on them a chance to attach itself to the new ones. A
	// hook registered here must therefore be written to run repeatedly - see
	// RunPhase for what "repeatedly" is allowed to mean.
	AfterResource Phase = 10

	// BeforeRouter is reached before the router is initialised, which is the
	// last point at which a module can still affect how routes are built.
	//
	// It is not the same point as the SetBefore registry: those callbacks run
	// after the router has been initialised, not before it.
	BeforeRouter Phase = 20

	// AfterListen is reached once the listening socket is accepting
	// connections - not merely once the goroutine that serves it was started.
	// A hook here can rely on the port being bound, because a failure to bind
	// has already been reported by then.
	AfterListen Phase = 30

	// BeforeExit is reached after the HTTP server has been shut down and
	// before the process returns, for work that must happen on the way out
	// but does not need the server.
	//
	// It is not a place to drain a load balancer: by the time it runs the
	// listener is already closed, so anything that depends on still being
	// reachable belongs somewhere this package does not currently offer.
	BeforeExit Phase = 40
)

func (Phase) String added in v2.6.0

func (p Phase) String() string

String names the phase, so that a log line reads AfterResource rather than 10. An unknown value prints as Phase(42) rather than as a wrong name, which is what the out-of-range reports in SetPhase and RunPhase carry.

type Queue

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

func (*Queue) Append

func (e *Queue) Append(message storage.Messager) error

Append 增加数据到生产者

func (*Queue) Register

func (e *Queue) Register(name string, f storage.ConsumerFunc)

Register 注册消费者

func (*Queue) Run

func (e *Queue) Run()

Run 运行

func (*Queue) Shutdown

func (e *Queue) Shutdown()

Shutdown 停止

func (*Queue) String

func (e *Queue) String() string

type Router

type Router struct {
	HttpMethod, RelativePath, Handler string
}

type Routers

type Routers struct {
	List []Router
}

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{}
	// GetHandlerFunc is GetMiddleware plus the gin.HandlerFunc assertion every
	// caller otherwise repeats, and false instead of a panic when the key is
	// unregistered or holds something else. See the well-known keys
	// JwtTokenCheck, RoleCheck and PermissionCheck.
	GetHandlerFunc(key string) (gin.HandlerFunc, bool)

	// 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

	// SetPhase registers a callback to run when the application reaches the
	// given life-cycle phase.
	SetPhase(p Phase, f func(), opts ...CallbackOption)
	// RunPhase executes the callbacks registered for a phase that have not
	// run yet, in registration order.
	RunPhase(p Phase)
	// PhaseSealed reports whether a phase has already run, i.e. whether a
	// further SetPhase for it would be dropped.
	PhaseSealed(p Phase) bool
	// BeginShutdown says the application is on its way out: SetPhase and
	// RunPhase stop doing anything for every phase but BeforeExit.
	BeginShutdown()
	// SetShutdown registers a cleanup callback for the BeforeExit phase,
	// taking the context that carries the shutdown budget.
	SetShutdown(f func(context.Context), opts ...CallbackOption)
	// RunShutdown runs the BeforeExit callbacks in reverse registration
	// order, returning ctx.Err() if the context ends first.
	RunShutdown(ctx context.Context) error
}

Jump to

Keyboard shortcuts

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