types

package
v0.1.25 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 19

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultPublisherOption = &PublisherOption{
		PublishDelayMessage: false,
	}

	DefaultSubscriberOption = &SubscriberOption{
		SubscribeDelayMessage: false,
	}
)

Functions

This section is empty.

Types

type AppServer added in v0.0.23

type AppServer interface {
	Start() error                               // 开始
	Stop(forced ...bool) error                  // 默认为优雅关闭, 如果forced为true, 则强制关闭
	HookPreStart(fns ...HookFunction) AppServer // 添加启动前的钩子函数
	HookPreStop(fns ...HookFunction) AppServer  // 添加停止前的钩子函数
}

type BulkOperateObjectRequest added in v0.1.25

type BulkOperateObjectRequest[TObjectId ObjectIdentifier] struct {
	Ids []TObjectId `json:"ids"`
}

type Capability

type Capability struct {
	Category ProviderCategory
	Name     string
	Module   fx.Option
}

Capability 能力提供者

type ConfigProvider added in v0.0.23

type ConfigProvider interface {
	Provider
	Unmarshal(configVar any, key ...string) error // 读取配置到变量configVar
	Get(key string) any                           // 获取配置项的值
}

type CreateObjectResponse added in v0.1.25

type CreateObjectResponse[TObjectId ObjectIdentifier] struct {
	Id TObjectId `json:"id"`
}

type CreateRefObjectRequest added in v0.1.25

type CreateRefObjectRequest[TObjectId ObjectIdentifier, TBizObject any] struct {
	Id   TObjectId  `json:"id"`
	Item TBizObject `json:"item"`
}

type DbBulkRetrieve added in v0.0.23

type DbBulkRetrieve[TObjectId ObjectIdentifier, ModelObject any] interface {
	BulkGet(ids []TObjectId) (map[TObjectId]ModelObject, error) // 批量获取对象
}

DbBulkRetrieve 批量读取

type DbClient added in v0.0.23

type DbClient interface {
	DbExecutor

	Get(dest interface{}, query string, args ...interface{}) error
	Select(dest interface{}, query string, args ...interface{}) error
	Rebind(query string) string
	Close() error
}

type DbCreate added in v0.0.23

type DbCreate[BizObject any, ModelObject any] interface {
	Create(bizObj BizObject) (ModelObject, error) // 创建对象
}

DbCreate 创建操作:C

type DbDelete added in v0.0.23

type DbDelete[TObjectId ObjectIdentifier] interface {
	Delete(id TObjectId) error // 删除对象
}

DbDelete 删除

type DbEdit added in v0.1.5

type DbEdit[TBizObject any] interface {
	Edit(bizObj TBizObject) error // 编辑对象
}

type DbExecutor added in v0.1.5

type DbExecutor interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

type DbOperation added in v0.0.23

type DbOperation[TObjectId ObjectIdentifier, TBizObject any, TModelObject any, TCondition any] interface {
	DbCreate[TBizObject, TModelObject]
	DbRetrieve[TObjectId, TModelObject, TCondition]
	DbUpdate[TModelObject]
	DbDelete[TObjectId]
}

type DbProvider added in v0.0.23

type DbProvider interface {
	Provider
	My() DbClient
	Master() DbClient
	Slave(i int) DbClient
	By(name string) DbClient
}

type DbRetrieve added in v0.0.23

type DbRetrieve[TObjectId ObjectIdentifier, TModelObject any, TCondition any] interface {
	Get(id TObjectId) (TModelObject, error)                                              // 获取对象
	Count(filters map[string]string) (int64, error)                                      // 统计对象
	List(filters map[string]string, list ...*protobuf.ListParam) ([]TModelObject, error) // 列出对象, list不传的时候获取所有对象
	GetQueryConditions(filters map[string]string) []TCondition                           // 获取查询条件
}

DbRetrieve 读取操作:R

type DbUpdate added in v0.0.23

type DbUpdate[TModelObject any] interface {
	Update(modelObj TModelObject) error // 更新某个字段
}

DbUpdate 更新:U

type DeleteRefObjectRequest added in v0.1.25

type DeleteRefObjectRequest[TObjectId ObjectIdentifier] struct {
	Id     TObjectId `json:"id"`
	ItemId TObjectId `json:"itemId"`
}

type EditRefObjectRequest added in v0.1.25

type EditRefObjectRequest[TObjectId ObjectIdentifier, TBizObject any] struct {
	Id   TObjectId  `json:"id"`
	Item TBizObject `json:"item"`
}

type GetRefObjectRequest added in v0.1.25

type GetRefObjectRequest[TObjectId ObjectIdentifier] struct {
	Id     TObjectId `json:"id"`
	ItemId TObjectId `json:"itemId"`
}

type HookFunction added in v0.0.23

type HookFunction func() error

type LoggerProvider added in v0.0.23

type LoggerProvider interface {
	Provider
	GetStdLogger() *log.Logger
	Log(keyvals ...interface{}) error
	Trace(msg string, keyvals ...interface{})
	Debug(msg string, keyvals ...interface{})
	Info(msg string, keyvals ...interface{})
	Warn(msg string, keyvals ...interface{})
	Error(msg string, keyvals ...interface{})
	Fatal(msg string, keyvals ...interface{})
	Panic(msg string, keyvals ...interface{})
}

type Message

type Message struct {
	// Payload is the message's payload.
	Payload Payload
	// contains filtered or unexported fields
}

Message is the basic transfer unit. Messages are emitted by Publishers and received by Subscribers.

func NewMessage

func NewMessage(payload Payload) *Message

NewMessage creates a new Message with payload.

func (*Message) Ack

func (m *Message) Ack() bool

Ack sends message's acknowledgement.

Ack is not blocking. Ack is idempotent. False is returned, if Nack is already sent.

func (*Message) Acked

func (m *Message) Acked() <-chan struct{}

Acked returns channel which is closed when acknowledgement is sent.

Usage:

select {
case <-message.Acked():
	// ack received
case <-message.Nacked():
	// nack received
}

func (*Message) Context

func (m *Message) Context() context.Context

Context returns the message's servicectx. To change the servicectx, use SetContext.

The returned servicectx is always non-nil; it defaults to the background servicectx.

func (*Message) Nack

func (m *Message) Nack() bool

Nack sends message's negative acknowledgement.

Nack is not blocking. Nack is idempotent. False is returned, if Ack is already sent.

func (*Message) Nacked

func (m *Message) Nacked() <-chan struct{}

Nacked returns channel which is closed when negative acknowledgement is sent.

Usage:

select {
case <-message.Acked():
	// ack received
case <-message.Nacked():
	// nack received
}

func (*Message) SetContext

func (m *Message) SetContext(ctx context.Context)

SetContext sets provided servicectx to the message.

type MessageQueueProvider added in v0.0.23

type MessageQueueProvider interface {
	Provider
	NewPublisher(name string, args ...*PublisherOption) (MessageQueuePublisher, error)
	NewSubscriber(name string, args ...*SubscriberOption) (MessageQueueSubscriber, error)
}

MessageQueueProvider 相同name的多个订阅者如果订阅同一个topic,则只有一个订阅者会收到消息 不同name的多个订阅者果订阅同一个topic,则所有订阅者都会收到消息

type MessageQueuePublisher added in v0.0.23

type MessageQueuePublisher interface {
	// Publish publishes provided messages to given topic.
	//
	// Publish can be synchronous or asynchronous - it depends on the implementation.
	//
	// Most publishers implementations don't support atomic publishing of messages.
	// This means that if publishing one of the messages fails, the next messages will not be published.
	//
	// Publish must be thread safe.
	Publish(topic string, messages [][]byte, delaySeconds ...int64) error
	// Close should flush unsent messages, if publisher is async.
	Close() error
}

type MessageQueueSubscriber added in v0.0.23

type MessageQueueSubscriber interface {
	// Subscribe returns output channel with messages from provided topic.
	// Channel is closed, when Close() was called on the subscriber.
	//
	// To receive the next message, `Ack()` must be called on the received message.
	// If message processing failed and message should be redelivered `Nack()` should be called.
	//
	// When provided ctx is cancelled, subscriber will close subscribe and close output channel.
	// Provided ctx is set to all produced messages.
	// When Nack or Ack is called on the message, servicectx of the message is canceled.
	Subscribe(ctx context.Context, topic string) (<-chan *Message, error)
	// Close closes all subscriptions with their output channels and flush offsets etc. when needed.
	Close() error
}

type ObjectIdentifier added in v0.1.25

type ObjectIdentifier interface {
	int64 | int32 | int | string
}

type OperateObjectRequest added in v0.1.25

type OperateObjectRequest[TObjectId ObjectIdentifier] struct {
	Id TObjectId `json:"id"`
}

type OssProvider added in v0.0.23

type OssProvider interface {
	Provider
	WithContentTypes(contentTypes []string) OssProvider                                   // 设置允许的文件类型
	WithMaxFileSize(fileSize int64) OssProvider                                           // 设置允许最大的文件大小
	WithSignExpiresIn(duration time.Duration) OssProvider                                 // 设置签名过期时间
	Upload(dir, filename string, data []byte) (string, error)                             // 上传文件
	GetPresignedURL(dir, filename, contentType string) (string, map[string]string, error) // 生成预签名URL, 返回URL,headers
	GetPostSignature(dir, filename string) (map[string]string, error)                     // 生成POST签名
}

type Payload

type Payload []byte

Payload is the Message's payload.

type Provider

type Provider interface {
	GetCapability() Capability // 获取能力
}

Provider 底层库能力提供者接口

type ProviderCategory

type ProviderCategory int
const (
	ProviderCategoryUnknown ProviderCategory = iota
	ProviderCategoryConfig
	ProviderCategoryLogger
	ProviderCategoryDb
	ProviderCategoryRedis
	ProviderCategoryMq
	ProviderCategoryOss
)

type PublisherOption

type PublisherOption struct {
	PublishDelayMessage bool
}

type QueryObjectRequest added in v0.1.25

type QueryObjectRequest struct {
	Filters map[string]string   `json:"filters,omitempty"`
	List    *protobuf.ListParam `json:"list,omitempty"`
}

type QueryObjectResponse added in v0.1.25

type QueryObjectResponse[TBizObject any] struct {
	Total int64        `json:"total"`
	Items []TBizObject `json:"items"`
}

type QueryRefObjectRequest added in v0.1.25

type QueryRefObjectRequest[TObjectId ObjectIdentifier] struct {
	Id      TObjectId           `json:"id"`
	Filters map[string]string   `json:"filters,omitempty"`
	List    *protobuf.ListParam `json:"list,omitempty"`
}

type QueryRefObjectResponse added in v0.1.25

type QueryRefObjectResponse[TBizObject any] struct {
	Total int64        `json:"total"`
	Items []TBizObject `json:"items"`
}

type RedisClient added in v0.0.23

type RedisClient interface {
	// general purpose
	Del(key string) error
	Dels(keys []string) error
	Exists(key string) (bool, error)
	Expire(key string, expire int) error
	Incr(key string) error
	IncrBy(key string, number int) error
	DecrBy(key string, number int) error
	Ttl(key string) (int64, error)
	Pipeline(commands []*RedisCommand) (reply interface{}, err error)
	Ping() error

	// Set operations
	Set(key string, value interface{}) error
	SetEx(key string, value interface{}, expire int) error

	// Get operations
	Get(key string) ([]byte, error)
	GetInt(key string) (int, error)
	GetInt64(key string) (int64, error)
	GetFloat64(key string) (float64, error)
	GetString(key string) (string, error)

	// HashMap operations
	HGetAll(key string) (map[string]string, error)
	HGet(key string, field any) ([]byte, error)
	HGetInt(key string, field string) (int, error)
	HGetInt64(key string, field string) (int64, error)
	HGetFloat64(key string, field string) (float64, error)
	HGetString(key string, field string) (string, error)
	HMGet(key string, fields []string) ([][]byte, error)
	HSet(key string, field interface{}, value interface{}) (int, error)
	HMSet(key string, args map[string]interface{}) error
	HDel(key string, field interface{}) (int, error)
	HDels(key string, fields []interface{}) (int, error)
	HLen(key string) (int, error)

	// set
	SIsMember(key string, member interface{}) (bool, error)
	SAdd(key string, members interface{}) error
	SRem(key string, members interface{}) error
	SInter(keys []string) ([]string, error)
	SUnion(keys []string) ([]string, error)
	SDiff(keys []string) ([]string, error)
	SMembers(key string) ([]string, error)

	// zset
	ZAdd(key string, score int64, member interface{}) error
	ZCard(key string) (int, error)
	ZRange(key string, min, max int64) ([]string, error)
	ZRemRangeByScore(key string, min, max interface{}) error
	ZRangeByScore(key string, min, max interface{}, withScores bool, list *protobuf.ListParam) ([]string, error)
	ZScore(key string, member interface{}) (int64, error)
	ZInterstore(newKey string, keys ...interface{}) (int64, error)
	ZIncrBy(key string, increment int64, member interface{}) error
	ZRem(destKey string, members ...interface{}) (int64, error)

	// list
	LPush(key string, values ...any) error
	RPush(key string, values ...any) error
	RPop(key string) ([]byte, error)
	LRangeInt64(key string, start, end int64) ([]int64, error)
	LRangeString(key string, start, end int64) ([]string, error)
	LLen(key string) (int64, error)
	Eval(scriptContent string, keys []interface{}, args []interface{}) (interface{}, error)

	// redis bloom
	BfExists(key string, item string) (exists bool, err error)
	BfAdd(key string, item string) (exists bool, err error)
	BfReserve(key string, errorRate float64, capacity uint64) (err error)
	BfAddMulti(key string, items []interface{}) ([]int64, error)
	BfExistsMulti(key string, items []interface{}) ([]int64, error)
}

type RedisCommand added in v0.0.23

type RedisCommand struct {
	Name string
	Args []interface{}
}

type RedisProvider added in v0.0.23

type RedisProvider interface {
	Provider
	My() RedisClient
	By(string) RedisClient
}

type RefDbBulkRetrieve added in v0.0.23

type RefDbBulkRetrieve[TObjectId ObjectIdentifier, TRefModelObject any] interface {
	BulkGet(id TObjectId, refIds []TObjectId) (map[TObjectId]TRefModelObject, error) // 批量获取对象
}

RefDbBulkRetrieve 批量读取关联对象

type RefDbCreate added in v0.0.23

type RefDbCreate[TObjectId ObjectIdentifier, TRefBizObject any, TRefModelObject any] interface {
	Create(id TObjectId, refBizObj TRefBizObject) (TRefModelObject, error) // 创建关联对象DAO
}

RefDbCreate 创建关联对象操作:C

type RefDbDelete added in v0.0.23

type RefDbDelete[TObjectId ObjectIdentifier] interface {
	Delete(id, refId TObjectId) error // 删除关联对象DAO
}

RefDbDelete 删除关联对象

type RefDbEdit added in v0.1.5

type RefDbEdit[TObjectId ObjectIdentifier, TRefBizObject any] interface {
	Edit(id TObjectId, refBizObj TRefBizObject) error // 编辑数据库关联对象DAO
}

type RefDbOperation added in v0.0.23

type RefDbOperation[TObjectId ObjectIdentifier, TRefBizObject any, TRefModelObject any, TCondition any] interface {
	RefDbCreate[TObjectId, TRefBizObject, TRefModelObject]
	RefDbRetrieve[TObjectId, TRefModelObject, TCondition]
	RefDbUpdate[TRefModelObject]
	RefDbDelete[TObjectId]
}

type RefDbRetrieve added in v0.0.23

type RefDbRetrieve[TObjectId ObjectIdentifier, TRefModelObject any, Condition any] interface {
	Get(id, refId TObjectId) (TRefModelObject, error)                                                           // 获取关联对象DAO
	Count(id TObjectId, refObjFilters map[string]string) (int64, error)                                         // 统计关联对象DAO
	List(id TObjectId, refObjFilters map[string]string, list ...*protobuf.ListParam) ([]TRefModelObject, error) // 列出关联对象DAO
	GetQueryConditions(id TObjectId, refObjFilters map[string]string) []Condition                               // 获取关联对象DAO
}

RefDbRetrieve 读取关联对象操作:R

type RefDbUpdate added in v0.0.23

type RefDbUpdate[TRefObjectModel any] interface {
	Update(refObjModel TRefObjectModel) error // 更新数据库关联对象
}

RefDbUpdate 更新关联对象:U

type ServiceCreate added in v0.1.5

type ServiceCreate[TBizObject any] interface {
	Create(ctx biz.Context, object TBizObject) (int64, error) // 创建业务对象
}

type ServiceDelete added in v0.1.5

type ServiceDelete[TObjectId ObjectIdentifier] interface {
	Delete(ctx biz.Context, id TObjectId) error // 删除业务对象
}

type ServiceOperation added in v0.1.5

type ServiceOperation[TObjectId ObjectIdentifier, TBizObject any] interface {
	ServiceCreate[TBizObject]
	ServiceRetrieve[TObjectId, TBizObject]
	ServiceUpdate[TBizObject]
	ServiceDelete[TObjectId]
}

type ServiceRetrieve added in v0.1.5

type ServiceRetrieve[TObjectId ObjectIdentifier, TBizObject any] interface {
	Get(ctx biz.Context, id TObjectId) (TBizObject, error)                                                      // 获取业务对象
	Query(ctx biz.Context, filters map[string]string, list ...*protobuf.ListParam) (int64, []TBizObject, error) // 查询业务对象
}

type ServiceUpdate added in v0.1.5

type ServiceUpdate[TBizObject any] interface {
	Edit(ctx biz.Context, bizObject TBizObject) error // 编辑业务对象
}

type SubscriberOption

type SubscriberOption struct {
	SubscribeDelayMessage bool
}

Jump to

Keyboard shortcuts

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