runtime

package
v2.4.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

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 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{}

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

Jump to

Keyboard shortcuts

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