runtime

package
v1.1.45 Latest Latest
Warning

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

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

Documentation

Index

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 NewConfig

func NewConfig() *Application

NewConfig 默认值

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 int, 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 int, crontab *cron.Cron) bool)

GetCrontab 获取所有map里的crontab数据

func (*Application) GetEngine

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

GetEngine 获取路由引擎

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

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

GetLogger 获取日志组件

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) 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) GetTenantCasbin added in v1.1.17

func (e *Application) GetTenantCasbin(tenantID int) *casbin.SyncedEnforcer

GetTenantCasbin 根据租户id获取casbin

func (*Application) GetTenantCrontab added in v1.1.17

func (e *Application) GetTenantCrontab(tenantID int) *cron.Cron

GetCrontabKey 根据key获取crontab

func (*Application) GetTenantDB added in v1.1.11

func (e *Application) GetTenantDB(tenantID int) *gorm.DB

GetTenantDB 向后兼容:优先返回 security-management 服务,否则返回默认 tenantDBs

func (*Application) GetTenantDBs added in v1.1.11

func (e *Application) GetTenantDBs(fn func(tenantID int, db *gorm.DB) bool)

GetTenantDBs 遍历所有租户数据库连接 使用举例,统计活跃的数据库连接数 count := 0

app.GetTenantDBs(func(tenantID int, db *gorm.DB) bool {
    if db != nil {
        count++
    }
    return true
})

fmt.Printf("活跃租户数量: %d\n", count)

func (*Application) GetTenantServiceDB added in v1.1.30

func (e *Application) GetTenantServiceDB(tenantID int, serviceCode string) *gorm.DB

GetTenantServiceDB 获取租户指定服务的数据库连接

func (*Application) GetTenantServiceDBs added in v1.1.30

func (e *Application) GetTenantServiceDBs(fn func(tenantID int, serviceCode string, db *gorm.DB) bool)

GetTenantServiceDBs 遍历所有租户服务数据库连接

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

func (e *Application) SetLogger(l *zap.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 设置队列适配器

func (*Application) SetTenantCasbin added in v1.1.17

func (e *Application) SetTenantCasbin(tenantID int, enforcer *casbin.SyncedEnforcer)

SetTenantCasbin 设置对应租户的casbin

func (*Application) SetTenantCrontab added in v1.1.17

func (e *Application) SetTenantCrontab(tenantID int, crontab *cron.Cron)

SetCrontab 设置对应key的crontab

func (*Application) SetTenantDB added in v1.1.11

func (e *Application) SetTenantDB(tenantID int, db *gorm.DB)

SetTenantDB 非CQRS时,设置租户数据库连接

func (*Application) SetTenantServiceDB added in v1.1.30

func (e *Application) SetTenantServiceDB(tenantID int, serviceCode string, db *gorm.DB)

SetTenantServiceDB 设置租户指定服务的数据库连接

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 Locker

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

func (*Locker) Lock

func (e *Locker) Lock(key string, ttl int64, options *redislock.Options) (*redislock.Lock, error)

Lock 返回分布式锁对象

func (*Locker) String

func (e *Locker) String() string

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 {
	// SetTenantDb 多db设置,⚠️SetTenantDbs不允许并发,可以根据自己的业务,例如app分库(用分表分库,或不同微服务实现)、host分库(多租户)
	SetTenantDB(tenantID int, db *gorm.DB)
	GetTenantDB(tenantID int) *gorm.DB
	GetTenantDBs(fn func(tenantID int, db *gorm.DB) bool)

	// SetTenantServiceDB 设置租户指定服务的数据库连接,预留暂未使用
	SetTenantServiceDB(tenantID int, serviceCode string, db *gorm.DB)
	// GetTenantServiceDB 获取租户指定服务的数据库连接,预留暂未使用
	GetTenantServiceDB(tenantID int, serviceCode string) *gorm.DB
	// GetTenantServiceDBs 遍历所有租户服务数据库连接,预留暂未使用
	GetTenantServiceDBs(fn func(tenantID int, serviceCode string, db *gorm.DB) bool)

	// SetTenantCasbin 设置对应租户的casbin
	SetTenantCasbin(tenantID int, enforcer *casbin.SyncedEnforcer)
	// GetTenantCasbin 根据租户id获取casbin
	GetTenantCasbin(tenantID int) *casbin.SyncedEnforcer
	// GetCasbins 获取所有casbin
	GetCasbins(fn func(tenantID int, 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 int, crontab *cron.Cron)
	GetTenantCrontab(tenantID int) *cron.Cron
	GetCrontabs(fn func(tenantID int, 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
}

Jump to

Keyboard shortcuts

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