events

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

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"
	EntityPrivateChannelShare = "private_channel_share"

	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 Publish

func Publish[T any](ctx context.Context, bus app.EventBus, topic Topic[T], payload T) error

func PublishAgentCreate

func PublishAgentCreate(ctx context.Context, bus app.EventBus, payload models.Agent) error

func PublishAgentDelete

func PublishAgentDelete(ctx context.Context, bus app.EventBus, payload models.Agent) error

func PublishAgentRegistered

func PublishAgentRegistered(ctx context.Context, bus app.EventBus, payload models.Agent) error

func PublishAgentRevoked

func PublishAgentRevoked(ctx context.Context, bus app.EventBus, payload models.Agent) error

func PublishAgentRouteCreate

func PublishAgentRouteCreate(ctx context.Context, bus app.EventBus, payload models.AgentRoute) error

func PublishAgentRouteDelete

func PublishAgentRouteDelete(ctx context.Context, bus app.EventBus, payload models.AgentRoute) error

func PublishAgentRouteUpdate

func PublishAgentRouteUpdate(ctx context.Context, bus app.EventBus, payload models.AgentRoute) error

func PublishAgentUpdate

func PublishAgentUpdate(ctx context.Context, bus app.EventBus, payload models.Agent) error

func PublishChannelCreate

func PublishChannelCreate(ctx context.Context, bus app.EventBus, payload models.Channel) error

func PublishChannelDelete

func PublishChannelDelete(ctx context.Context, bus app.EventBus, payload models.Channel) error

func PublishChannelUpdate

func PublishChannelUpdate(ctx context.Context, bus app.EventBus, payload models.Channel) error

func PublishEntity

func PublishEntity[T any](ctx context.Context, bus app.EventBus, entity, action string, payload T) error

func PublishModelCreate

func PublishModelCreate(ctx context.Context, bus app.EventBus, payload models.ModelConfig) error

func PublishModelDelete

func PublishModelDelete(ctx context.Context, bus app.EventBus, payload models.ModelConfig) error

func PublishModelUpdate

func PublishModelUpdate(ctx context.Context, bus app.EventBus, payload models.ModelConfig) error

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 PublishScriptCreate(ctx context.Context, bus app.EventBus, payload models.AdminScript) error

func PublishScriptDelete added in v0.0.6

func PublishScriptDelete(ctx context.Context, bus app.EventBus, payload models.AdminScript) error

func PublishScriptUpdate added in v0.0.6

func PublishScriptUpdate(ctx context.Context, bus app.EventBus, payload models.AdminScript) error

func PublishSettingUpdate

func PublishSettingUpdate(ctx context.Context, bus app.EventBus, payload models.Setting) error

func PublishSyncEvent

func PublishSyncEvent(ctx context.Context, bus app.EventBus, entity, action string, payload protocol.SyncPushParams) error

func PublishSyncFullSyncRequested

func PublishSyncFullSyncRequested(ctx context.Context, bus app.EventBus) error

func PublishTokenCreate

func PublishTokenCreate(ctx context.Context, bus app.EventBus, payload models.Token) error

func PublishTokenDelete

func PublishTokenDelete(ctx context.Context, bus app.EventBus, payload models.Token) error

func PublishTokenUpdate

func PublishTokenUpdate(ctx context.Context, bus app.EventBus, payload models.Token) error

func PublishUsageCompleted

func PublishUsageCompleted(ctx context.Context, bus app.EventBus, payload protocol.UsageLogEntry) error

func PublishUsageReported

func PublishUsageReported(ctx context.Context, bus app.EventBus, payload protocol.UsageReport) error

func PublishUserQuotaDepleted

func PublishUserQuotaDepleted(ctx context.Context, bus app.EventBus, payload models.User) error

func PublishUserQuotaSync added in v0.0.8

func PublishUserQuotaSync(ctx context.Context, bus app.EventBus, payload protocol.UserQuotaSync) error

func Subscribe

func Subscribe[T any](bus app.EventBus, topic Topic[T], handler func(context.Context, T) error) (eventbus.Subscription, error)

func SubscribePattern

func SubscribePattern[T any](bus app.EventBus, pattern Pattern[T], handler func(context.Context, T) error) (eventbus.Subscription, error)

func SubscribeSyncFullSyncRequested

func SubscribeSyncFullSyncRequested(bus app.EventBus, handler func(context.Context) 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 SubscribeUserQuotaDepleted

func SubscribeUserQuotaDepleted(bus app.EventBus, handler func(context.Context, models.User) 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 JSONCodec

type JSONCodec struct{}

func (JSONCodec) Marshal

func (JSONCodec) Marshal(v any) ([]byte, error)

func (JSONCodec) Unmarshal

func (JSONCodec) Unmarshal(data []byte, out any) error

type Pattern

type Pattern[T any] struct {
	// contains filtered or unexported fields
}

func (Pattern[T]) Value

func (p Pattern[T]) Value() string

type PayloadCodec

type PayloadCodec interface {
	Marshal(any) ([]byte, error)
	Unmarshal([]byte, any) error
}

type Topic

type Topic[T any] struct {
	// contains filtered or unexported fields
}

func DynamicTopic

func DynamicTopic[T any](entity, action string) Topic[T]

func SyncPushTopic

func SyncPushTopic(entity, action string) Topic[protocol.SyncPushParams]

func (Topic[T]) Value

func (t Topic[T]) Value() string

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 TypedPatternSubscriber[T any] interface {
	SubscribePattern(pattern Pattern[T], handler func(context.Context, T) error) (eventbus.Subscription, error)
}

type TypedPublisher

type TypedPublisher[T any] interface {
	Publish(ctx context.Context, topic Topic[T], payload T) error
}

type TypedSubscriber

type TypedSubscriber[T any] interface {
	Subscribe(topic Topic[T], handler func(context.Context, T) error) (eventbus.Subscription, error)
}

Jump to

Keyboard shortcuts

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