Documentation
¶
Index ¶
- func GetConn(ctx context.Context) bun.Conn
- func GetDB() *bun.DB
- func LoadExt(extensions ...string)
- func Override(name string, extFunc func() Ext)
- func Register(name string, extFunc func() Ext)
- func SetCollectionDBResolver(r CollectionDBResolver)
- func SetNotifyTypeResolver(r NotifyTypeResolver)
- type ApolloExtension
- type CollectionDBResolver
- type DatabaseRepository
- type Ext
- type Getter
- type MongoExt
- func (m *MongoExt) Aggregate(ctx context.Context, collectionName string, pipeline any, out any) error
- func (m *MongoExt) Count(ctx context.Context, collectionName string, selector bson.M) (int64, error)
- func (m *MongoExt) DeleteMany(ctx context.Context, collectionName string, selector bson.M) error
- func (m *MongoExt) EnsureIndex(ctx context.Context, collectionName string, models []mongodriver.IndexModel) error
- func (m *MongoExt) FindAll(ctx context.Context, collectionName string, selector bson.M, result any) error
- func (m *MongoExt) FindOne(ctx context.Context, collectionName string, selector bson.M, result any) error
- func (m *MongoExt) FindPage(ctx context.Context, collectionName string, selector bson.M, result any, ...) (int64, error)
- func (m *MongoExt) FindPageWithSort(ctx context.Context, collectionName string, selector bson.M, result any, ...) (int64, error)
- func (m *MongoExt) Init(ctx context.Context) error
- func (m *MongoExt) Insert(ctx context.Context, collectionName string, data any) error
- func (m *MongoExt) UpdateMany(ctx context.Context, collectionName string, selector, updater bson.M) error
- func (m *MongoExt) UpdateOne(ctx context.Context, collectionName string, selector, updater bson.M) error
- func (m *MongoExt) UpsertOne(ctx context.Context, collectionName string, selector, updater bson.M) error
- type MongoExtConfig
- type MySQLExtension
- type NotifyManager
- type NotifyTypeResolver
- type RedisExtension
- func (r *RedisExtension) Del(ctx context.Context, keys ...string) (int64, error)
- func (r *RedisExtension) Get(ctx context.Context, key string) (Getter, error)
- func (r *RedisExtension) HGet(ctx context.Context, key, field string) (string, error)
- func (r *RedisExtension) HGetAll(ctx context.Context, key string) (map[string]string, error)
- func (r *RedisExtension) HSet(ctx context.Context, key string, value ...any) error
- func (r *RedisExtension) HSetField(ctx context.Context, key, field string, value any) error
- func (r *RedisExtension) Init(ctx context.Context) error
- func (r *RedisExtension) Set(ctx context.Context, key string, value any) error
- func (r *RedisExtension) SetEx(ctx context.Context, key string, value any, expiration time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Override ¶
Override replaces an existing extension implementation. It is the explicit counterpart of Register for callers that want to customize a built-in extension. It panics if no implementation was registered for the name yet, so typos surface early instead of silently registering a new entry.
func Register ¶
Register registers a default extension implementation. Built-in extensions in go-tools call this in their init(). A caller may replace a default implementation by calling Override with the same name (Go runs the caller's init() after imported packages, so the caller wins).
func SetCollectionDBResolver ¶
func SetCollectionDBResolver(r CollectionDBResolver)
SetCollectionDBResolver overrides the collection->db resolver used by MongoExt.
func SetNotifyTypeResolver ¶
func SetNotifyTypeResolver(r NotifyTypeResolver)
SetNotifyTypeResolver overrides the typeName->senderType resolver used by NotifyExt.WithNotifierByName.
Types ¶
type ApolloExtension ¶
func Apollo ¶
func Apollo() ApolloExtension
type CollectionDBResolver ¶
type DatabaseRepository ¶
type DatabaseRepository interface {
FindAll(ctx context.Context, collectionName string, selector bson.M, result any) error
FindOne(ctx context.Context, collectionName string, selector bson.M, result any) error
UpsertOne(ctx context.Context, collectionName string, selector bson.M, update bson.M) error
UpdateMany(ctx context.Context, collectionName string, selector bson.M, update bson.M) error
DeleteMany(ctx context.Context, collectionName string, selector bson.M) error
Insert(ctx context.Context, collectionName string, data any) error
}
type Ext ¶
func NewLoggerExt ¶
func NewLoggerExt() Ext
func NewMongoExt ¶
func NewMongoExt() Ext
func NewMySQLExtension ¶
func NewMySQLExtension() Ext
func NewNotifyExt ¶
func NewNotifyExt() Ext
func NewRedisExtension ¶
func NewRedisExtension() Ext
type MongoExt ¶
type MongoExt struct {
// contains filtered or unexported fields
}
var (
MgoExt *MongoExt
)
func (*MongoExt) Aggregate ¶
func (m *MongoExt) Aggregate(ctx context.Context, collectionName string, pipeline any, out any) error
Aggregate runs an aggregation pipeline against the collection and decodes all results into out (a slice). Mirrors the FindAll decode contract.
func (*MongoExt) DeleteMany ¶
func (*MongoExt) EnsureIndex ¶
func (m *MongoExt) EnsureIndex(ctx context.Context, collectionName string, models []mongodriver.IndexModel) error
func (*MongoExt) FindPageWithSort ¶ added in v0.2.2
func (m *MongoExt) FindPageWithSort(ctx context.Context, collectionName string, selector bson.M, result any, page, limit int64, sort bson.D) (int64, error)
FindPageWithSort 与 FindPage 相同,但允许调用方指定排序。sort 为空时缺省 _id 升序,保证分页顺序稳定。page/limit 非正数时钳制为 1/10,避免负数产生 非法 skip/limit。
func (*MongoExt) UpdateMany ¶
type MongoExtConfig ¶
type MongoExtConfig struct {
Uri string `json:"uri"`
}
type MySQLExtension ¶
type MySQLExtension struct {
// contains filtered or unexported fields
}
var (
MySQLExt *MySQLExtension
)
func (*MySQLExtension) Watch ¶
func (m *MySQLExtension) Watch() error
type NotifyManager ¶
type NotifyManager interface {
Ext
Register(name notify2.NotifySenderType, notifier notify.Notifier)
Unregister(name notify2.NotifySenderType)
Get(name notify2.NotifySenderType) (notify.NotifierWrapper, bool)
WithNotifier(ctx context.Context, senderType notify2.NotifySenderType) notify.NotifierWrapper
WithNotifierByName(ctx context.Context, typeName string) notify.NotifierWrapper
Send(ctx context.Context, name notify2.NotifySenderType, opts ...notify.Option) error
Broadcast(ctx context.Context, opts ...notify.Option) map[notify2.NotifySenderType]error
Close() error
}
func Notifier ¶
func Notifier() NotifyManager
type NotifyTypeResolver ¶
type NotifyTypeResolver func(typeName string) notify2.NotifySenderType
NotifyTypeResolver maps a type name string to a NotifySenderType. Callers whose mapping comes from a business apollo key (e.g. backend's NotifyConfig) should inject it via SetNotifyTypeResolver before LoadExt.
type RedisExtension ¶
type RedisExtension struct {
// contains filtered or unexported fields
}
var (
RedisExt *RedisExtension
)
func (*RedisExtension) HGet ¶
HGet returns the value of a single hash field. It returns ("", nil) when the field does not exist (redis.Nil is treated as a normal miss, not an error).
func (*RedisExtension) HGetAll ¶
HGetAll returns all fields and values of a hash key as a map. An empty map is returned when the key does not exist.
func (*RedisExtension) HSetField ¶
HSetField sets a single hash field. This is the field-scoped counterpart of the variadic HSet above, for callers that store one field at a time under a hash key (e.g. per-bucket aggregation state).