ext

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConn

func GetConn(ctx context.Context) bun.Conn

func GetDB

func GetDB() *bun.DB

func LoadExt

func LoadExt(extensions ...string)

func Override

func Override(name string, extFunc func() Ext)

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

func Register(name string, extFunc func() Ext)

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

type ApolloExtension interface {
	Ext
	mananger.Manager
}

func Apollo

func Apollo() ApolloExtension

type CollectionDBResolver

type CollectionDBResolver func(collectionName string) string

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

type Ext interface {
	Init(context.Context) error
}

func NewCatExt

func NewCatExt() 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 Getter

type Getter interface {
	String(args ...string) string
	Empty() bool
}

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

func (m *MongoExt) Count(ctx context.Context, collectionName string, selector bson.M) (int64, error)

func (*MongoExt) DeleteMany

func (m *MongoExt) DeleteMany(ctx context.Context, collectionName string, selector bson.M) error

func (*MongoExt) EnsureIndex

func (m *MongoExt) EnsureIndex(ctx context.Context, collectionName string, models []mongodriver.IndexModel) error

func (*MongoExt) FindAll

func (m *MongoExt) FindAll(ctx context.Context, collectionName string, selector bson.M, result any) error

func (*MongoExt) FindOne

func (m *MongoExt) FindOne(ctx context.Context, collectionName string, selector bson.M, result any) error

func (*MongoExt) FindPage

func (m *MongoExt) FindPage(ctx context.Context, collectionName string, selector bson.M, result any, page, limit int64) (int64, 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) Init

func (m *MongoExt) Init(ctx context.Context) error

func (*MongoExt) Insert

func (m *MongoExt) Insert(ctx context.Context, collectionName string, data any) error

func (*MongoExt) UpdateMany

func (m *MongoExt) UpdateMany(ctx context.Context, collectionName string, selector, updater bson.M) error

func (*MongoExt) UpdateOne

func (m *MongoExt) UpdateOne(ctx context.Context, collectionName string, selector, updater bson.M) error

func (*MongoExt) UpsertOne

func (m *MongoExt) UpsertOne(ctx context.Context, collectionName string, selector, updater bson.M) error

type MongoExtConfig

type MongoExtConfig struct {
	Uri string `json:"uri"`
}

type MySQLExtension

type MySQLExtension struct {
	// contains filtered or unexported fields
}
var (
	MySQLExt *MySQLExtension
)

func (*MySQLExtension) Init

func (m *MySQLExtension) Init(ctx context.Context) error

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

func (r *RedisExtension) Del(ctx context.Context, keys ...string) (int64, error)

Del removes one or more keys. Returns the number of keys removed.

func (*RedisExtension) Get

func (r *RedisExtension) Get(ctx context.Context, key string) (Getter, error)

func (*RedisExtension) HGet

func (r *RedisExtension) HGet(ctx context.Context, key, field string) (string, error)

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

func (r *RedisExtension) HGetAll(ctx context.Context, key string) (map[string]string, error)

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

func (r *RedisExtension) HSet(ctx context.Context, key string, value ...any) error

func (*RedisExtension) HSetField

func (r *RedisExtension) HSetField(ctx context.Context, key, field string, value any) error

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

func (*RedisExtension) Init

func (r *RedisExtension) Init(ctx context.Context) error

func (*RedisExtension) Set

func (r *RedisExtension) Set(ctx context.Context, key string, value any) error

func (*RedisExtension) SetEx

func (r *RedisExtension) SetEx(ctx context.Context, key string, value any, expiration time.Duration) error

Jump to

Keyboard shortcuts

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