Documentation
¶
Index ¶
- Constants
- Variables
- func Publish[T any](ctx context.Context, bus app.EventBus, topic Topic[T], payload T) error
- func PublishAgentCreate(ctx context.Context, bus app.EventBus, payload models.Agent) error
- func PublishAgentDelete(ctx context.Context, bus app.EventBus, payload models.Agent) error
- func PublishAgentRegistered(ctx context.Context, bus app.EventBus, payload models.Agent) error
- func PublishAgentRevoked(ctx context.Context, bus app.EventBus, payload models.Agent) error
- func PublishAgentRouteCreate(ctx context.Context, bus app.EventBus, payload models.AgentRoute) error
- func PublishAgentRouteDelete(ctx context.Context, bus app.EventBus, payload models.AgentRoute) error
- func PublishAgentRouteUpdate(ctx context.Context, bus app.EventBus, payload models.AgentRoute) error
- func PublishAgentUpdate(ctx context.Context, bus app.EventBus, payload models.Agent) error
- func PublishChannelCreate(ctx context.Context, bus app.EventBus, payload models.Channel) error
- func PublishChannelDelete(ctx context.Context, bus app.EventBus, payload models.Channel) error
- func PublishChannelUpdate(ctx context.Context, bus app.EventBus, payload models.Channel) error
- func PublishEntity[T any](ctx context.Context, bus app.EventBus, entity, action string, payload T) error
- func PublishModelCreate(ctx context.Context, bus app.EventBus, payload models.ModelConfig) error
- func PublishModelDelete(ctx context.Context, bus app.EventBus, payload models.ModelConfig) error
- func PublishModelUpdate(ctx context.Context, bus app.EventBus, payload models.ModelConfig) error
- func PublishPrivateChannelInvalidate(ctx context.Context, bus app.EventBus, affectedUserIDs []uint) error
- func PublishScriptCreate(ctx context.Context, bus app.EventBus, payload models.AdminScript) error
- func PublishScriptDelete(ctx context.Context, bus app.EventBus, payload models.AdminScript) error
- func PublishScriptUpdate(ctx context.Context, bus app.EventBus, payload models.AdminScript) error
- func PublishSettingUpdate(ctx context.Context, bus app.EventBus, payload models.Setting) error
- func PublishSyncEvent(ctx context.Context, bus app.EventBus, entity, action string, ...) error
- func PublishSyncFullSyncRequested(ctx context.Context, bus app.EventBus) error
- func PublishTokenCreate(ctx context.Context, bus app.EventBus, payload models.Token) error
- func PublishTokenDelete(ctx context.Context, bus app.EventBus, payload models.Token) error
- func PublishTokenUpdate(ctx context.Context, bus app.EventBus, payload models.Token) error
- func PublishUsageCompleted(ctx context.Context, bus app.EventBus, payload protocol.UsageLogEntry) error
- func PublishUsageReported(ctx context.Context, bus app.EventBus, payload protocol.UsageReport) error
- func PublishUserQuotaDepleted(ctx context.Context, bus app.EventBus, payload models.User) error
- func PublishUserQuotaSync(ctx context.Context, bus app.EventBus, payload protocol.UserQuotaSync) error
- func Subscribe[T any](bus app.EventBus, topic Topic[T], handler func(context.Context, T) error) (eventbus.Subscription, error)
- func SubscribePattern[T any](bus app.EventBus, pattern Pattern[T], handler func(context.Context, T) error) (eventbus.Subscription, error)
- func SubscribeSyncFullSyncRequested(bus app.EventBus, handler func(context.Context) error) (eventbus.Subscription, error)
- func SubscribeSyncPushPattern(bus app.EventBus, pattern Pattern[protocol.SyncPushParams], ...) (eventbus.Subscription, error)
- func SubscribeUsageCompleted(bus app.EventBus, handler func(context.Context, protocol.UsageLogEntry) error) (eventbus.Subscription, error)
- func SubscribeUsageReported(bus app.EventBus, handler func(context.Context, protocol.UsageReport) error) (eventbus.Subscription, error)
- func SubscribeUserQuotaDepleted(bus app.EventBus, handler func(context.Context, models.User) error) (eventbus.Subscription, error)
- func SubscribeUserQuotaSync(bus app.EventBus, handler func(context.Context, protocol.UserQuotaSync) error) (eventbus.Subscription, error)
- type JSONCodec
- type Pattern
- type PayloadCodec
- type Topic
- type TopicRegistry
- type TypedPatternSubscriber
- type TypedPublisher
- type TypedSubscriber
Constants ¶
View Source
const ( EntityToken = "token" EntityChannel = "channel" EntityModel = "model" EntityModelV1 = "model_config" // legacy full-sync entity name EntitySetting = "setting" EntityAgent = "agent" EntityAgentRoute = "agent_route" EntityRequestLimiter = "request_limiter" EntityLimiterBinding = "limiter_binding" EntityModelRouting = "model_routing" EntityUserRoutings = "user_routings" EntityTokenRoutings = "token_routings" EntitySync = "sync" EntityUserGroup = "user_group" EntityUser = "user" EntityAPIService = "api_service" EntityAPIRoute = "api_route" EntityAPIUpstream = "api_upstream" EntityAPIRole = "api_role" EntityUserGroupAPIRoleSet = "user_group_api_role_set" EntityUserAPIRoleSet = "user_api_role_set" EntityTokenAPIRoleSet = "token_api_role_set" EntityPrivateChannel = "private_channel" EntityScript = "script" )
Entity 常量。
View Source
const ( ActionCreate = "create" ActionUpdate = "update" ActionDelete = "delete" ActionInvalidate = "invalidate" )
CRUD action 常量。
Variables ¶
View Source
var ( TokenCreateTopic = newTopic[models.Token](topicTokenCreate) TokenUpdateTopic = newTopic[models.Token](topicTokenUpdate) TokenDeleteTopic = newTopic[models.Token](topicTokenDelete) ChannelCreateTopic = newTopic[models.Channel](topicChannelCreate) ChannelUpdateTopic = newTopic[models.Channel](topicChannelUpdate) ChannelDeleteTopic = newTopic[models.Channel](topicChannelDelete) ModelCreateTopic = newTopic[models.ModelConfig](topicModelCreate) ModelUpdateTopic = newTopic[models.ModelConfig](topicModelUpdate) ModelDeleteTopic = newTopic[models.ModelConfig](topicModelDelete) AgentRevokedTopic = newTopic[models.Agent](topicAgentRevoked) AgentRegisteredTopic = newTopic[models.Agent](topicAgentRegistered) UsageReportedTopic = newTopic[protocol.UsageReport](topicUsageReported) UsageCompletedTopic = newTopic[protocol.UsageLogEntry](topicUsageCompleted) UserQuotaDepletedTopic = newTopic[models.User](topicUserQuotaDepleted) UserQuotaSyncTopic = newTopic[protocol.UserQuotaSync](topicUserQuotaSync) SettingUpdateTopic = newTopic[models.Setting](topicSettingUpdate) SyncFullSyncRequestedTopic = newTopic[struct{}](topicSyncFullSyncRequested) TokenAllPattern = newPattern[models.Token](patternTokenAll) ChannelAllPattern = newPattern[models.Channel](patternChannelAll) ModelAllPattern = newPattern[models.ModelConfig](patternModelAll) SyncTokenAllPattern = newPattern[protocol.SyncPushParams](patternSyncTokenAll) SyncChannelAllPattern = newPattern[protocol.SyncPushParams](patternSyncChannelAll) SyncModelAllPattern = newPattern[protocol.SyncPushParams](patternSyncModelAll) SyncModelConfigAllPattern = newPattern[protocol.SyncPushParams](patternSyncModelConfigAll) SyncSettingAllPattern = newPattern[protocol.SyncPushParams](patternSyncSettingAll) AgentCreateTopic = newTopic[models.Agent](topicAgentCreate) AgentUpdateTopic = newTopic[models.Agent](topicAgentUpdate) AgentDeleteTopic = newTopic[models.Agent](topicAgentDelete) AgentAllPattern = newPattern[models.Agent](patternAgentAll) SyncAgentAllPattern = newPattern[protocol.SyncPushParams](patternSyncAgentAll) AgentRouteCreateTopic = newTopic[models.AgentRoute](topicAgentRouteCreate) AgentRouteUpdateTopic = newTopic[models.AgentRoute](topicAgentRouteUpdate) AgentRouteDeleteTopic = newTopic[models.AgentRoute](topicAgentRouteDelete) AgentRouteAllPattern = newPattern[models.AgentRoute](patternAgentRouteAll) SyncAgentRouteAllPattern = newPattern[protocol.SyncPushParams](patternSyncAgentRouteAll) RequestLimiterCreateTopic = newTopic[models.RequestLimiter](topicRequestLimiterCreate) RequestLimiterUpdateTopic = newTopic[models.RequestLimiter](topicRequestLimiterUpdate) RequestLimiterDeleteTopic = newTopic[models.RequestLimiter](topicRequestLimiterDelete) LimiterBindingCreateTopic = newTopic[models.LimiterBinding](topicLimiterBindingCreate) LimiterBindingUpdateTopic = newTopic[models.LimiterBinding](topicLimiterBindingUpdate) LimiterBindingDeleteTopic = newTopic[models.LimiterBinding](topicLimiterBindingDelete) SyncRequestLimiterAllPattern = newPattern[protocol.SyncPushParams](patternSyncRequestLimiterAll) SyncLimiterBindingAllPattern = newPattern[protocol.SyncPushParams](patternSyncLimiterBindingAll) ModelRoutingCreateTopic = newTopic[models.ModelRouting](topicModelRoutingCreate) ModelRoutingUpdateTopic = newTopic[models.ModelRouting](topicModelRoutingUpdate) ModelRoutingDeleteTopic = newTopic[models.ModelRouting](topicModelRoutingDelete) ModelRoutingAllPattern = newPattern[models.ModelRouting](patternModelRoutingAll) SyncModelRoutingAllPattern = newPattern[protocol.SyncPushParams](patternSyncModelRoutingAll) UserGroupCreateTopic = newTopic[models.UserGroup](topicUserGroupCreate) UserGroupUpdateTopic = newTopic[models.UserGroup](topicUserGroupUpdate) UserGroupDeleteTopic = newTopic[models.UserGroup](topicUserGroupDelete) UserSyncUpdateTopic = newTopic[protocol.SyncedUser](topicUserSyncUpdate) UserSyncDeleteTopic = newTopic[protocol.SyncedUser](topicUserSyncDelete) SyncUserGroupAllPattern = newPattern[protocol.SyncPushParams](patternSyncUserGroupAll) SyncUserAllPattern = newPattern[protocol.SyncPushParams](patternSyncUserAll) SyncPrivateChannelAllPattern = newPattern[protocol.SyncPushParams](patternSyncPrivateChannelAll) PrivateChannelInvalidateTopic = newTopic[protocol.PrivateChannelInvalidatePayload](entityTopic(EntityPrivateChannel, ActionInvalidate)) ScriptCreateTopic = newTopic[models.AdminScript](topicScriptCreate) ScriptUpdateTopic = newTopic[models.AdminScript](topicScriptUpdate) ScriptDeleteTopic = newTopic[models.AdminScript](topicScriptDelete) SyncScriptAllPattern = newPattern[protocol.SyncPushParams](patternSyncScriptAll) SyncAPIServiceAllPattern = newPattern[protocol.SyncPushParams](patternSyncAPIServiceAll) SyncAPIRouteAllPattern = newPattern[protocol.SyncPushParams](patternSyncAPIRouteAll) SyncAPIUpstreamAllPattern = newPattern[protocol.SyncPushParams](patternSyncAPIUpstreamAll) SyncAPIRoleAllPattern = newPattern[protocol.SyncPushParams](patternSyncAPIRoleAll) SyncUserAPIRoleSetAllPattern = newPattern[protocol.SyncPushParams](patternSyncUserAPIRoleSetAll) SyncUserGroupAPIRoleSetAllPattern = newPattern[protocol.SyncPushParams](patternSyncUserGroupAPIRoleSetAll) SyncTokenAPIRoleSetAllPattern = newPattern[protocol.SyncPushParams](patternSyncTokenAPIRoleSetAll) APIServiceCreateTopic = newTopic[protocol.SyncedAPIService](topicAPIServiceCreate) APIServiceUpdateTopic = newTopic[protocol.SyncedAPIService](topicAPIServiceUpdate) APIServiceDeleteTopic = newTopic[protocol.SyncedAPIService](topicAPIServiceDelete) APIRouteCreateTopic = newTopic[protocol.SyncedAPIRoute](topicAPIRouteCreate) APIRouteUpdateTopic = newTopic[protocol.SyncedAPIRoute](topicAPIRouteUpdate) APIRouteDeleteTopic = newTopic[protocol.SyncedAPIRoute](topicAPIRouteDelete) APIUpstreamCreateTopic = newTopic[protocol.SyncedAPIUpstream](topicAPIUpstreamCreate) APIUpstreamUpdateTopic = newTopic[protocol.SyncedAPIUpstream](topicAPIUpstreamUpdate) APIUpstreamDeleteTopic = newTopic[protocol.SyncedAPIUpstream](topicAPIUpstreamDelete) APIRoleCreateTopic = newTopic[protocol.SyncedAPIRole](topicAPIRoleCreate) APIRoleUpdateTopic = newTopic[protocol.SyncedAPIRole](topicAPIRoleUpdate) APIRoleDeleteTopic = newTopic[protocol.SyncedAPIRole](topicAPIRoleDelete) UserAPIRolesSyncedTopic = newTopic[protocol.APIRoleSetInvalidate](topicUserAPIRolesSynced) UserGroupAPIRolesSyncedTopic = newTopic[protocol.APIRoleSetFetchResult](topicUserGroupAPIRolesSynced) UserGroupAPIRolesDeletedTopic = newTopic[protocol.APIRoleSetFetchResult](topicUserGroupAPIRolesDeleted) TokenAPIRolesSyncedTopic = newTopic[protocol.APIRoleSetInvalidate](topicTokenAPIRolesSynced) )
Functions ¶
func PublishAgentCreate ¶
func PublishAgentDelete ¶
func PublishAgentRegistered ¶
func PublishAgentRevoked ¶
func PublishAgentRouteCreate ¶
func PublishAgentRouteDelete ¶
func PublishAgentRouteUpdate ¶
func PublishAgentUpdate ¶
func PublishChannelCreate ¶
func PublishChannelDelete ¶
func PublishChannelUpdate ¶
func PublishEntity ¶
func PublishModelCreate ¶
func PublishModelDelete ¶
func PublishModelUpdate ¶
func PublishPrivateChannelInvalidate ¶ added in v0.0.2
func PublishPrivateChannelInvalidate(ctx context.Context, bus app.EventBus, affectedUserIDs []uint) error
PublishPrivateChannelInvalidate notifies agents to drop cached visiblePrivateChannels for the listed users. Callers (master CRUD/share handlers) expand (owner ∪ share→user ∪ share→group members) into affectedUserIDs before calling.
func PublishScriptCreate ¶ added in v0.0.6
func PublishScriptDelete ¶ added in v0.0.6
func PublishScriptUpdate ¶ added in v0.0.6
func PublishSettingUpdate ¶
func PublishSyncEvent ¶
func PublishTokenCreate ¶
func PublishTokenDelete ¶
func PublishTokenUpdate ¶
func PublishUsageCompleted ¶
func PublishUsageReported ¶
func PublishUserQuotaSync ¶ added in v0.0.8
func SubscribePattern ¶
func SubscribeSyncPushPattern ¶
func SubscribeSyncPushPattern(bus app.EventBus, pattern Pattern[protocol.SyncPushParams], handler func(context.Context, protocol.SyncPushParams) error) (eventbus.Subscription, error)
func SubscribeUsageCompleted ¶
func SubscribeUsageCompleted(bus app.EventBus, handler func(context.Context, protocol.UsageLogEntry) error) (eventbus.Subscription, error)
func SubscribeUsageReported ¶
func SubscribeUsageReported(bus app.EventBus, handler func(context.Context, protocol.UsageReport) error) (eventbus.Subscription, error)
func SubscribeUserQuotaSync ¶ added in v0.0.8
func SubscribeUserQuotaSync(bus app.EventBus, handler func(context.Context, protocol.UserQuotaSync) error) (eventbus.Subscription, error)
Types ¶
type PayloadCodec ¶
type Topic ¶
type Topic[T any] struct { // contains filtered or unexported fields }
func DynamicTopic ¶
func SyncPushTopic ¶
func SyncPushTopic(entity, action string) Topic[protocol.SyncPushParams]
type TopicRegistry ¶
type TopicRegistry interface {
PayloadType(topic string) (reflect.Type, bool)
Validate(topic string, payload any) error
}
var DefaultRegistry TopicRegistry = NewRegistry()
func NewRegistry ¶
func NewRegistry() TopicRegistry
type TypedPatternSubscriber ¶
type TypedPublisher ¶
type TypedSubscriber ¶
Click to show internal directories.
Click to hide internal directories.