Documentation
¶
Overview ¶
* @Author: hongliu * @Date: 2022-09-16 10:25:38 * @LastEditors: hongliu * @LastEditTime: 2022-09-16 14:16:44 * @FilePath: \common\infra\common\config.go * @Description: 配置模块通用数据定义 * * Copyright (c) 2022 by 洪流, All Rights Reserved.
* @Author: hongliu * @Date: 2022-09-16 14:17:23 * @LastEditors: hongliu * @LastEditTime: 2022-10-20 14:47:08 * @FilePath: \common\infra\common\config_source.go * @Description: 配置数据源接口抽象定义 * * Copyright (c) 2022 by 洪流, All Rights Reserved.
* @Author: hongliu * @Date: 2022-09-20 16:36:03 * @LastEditors: hongliu * @LastEditTime: 2022-09-21 11:26:50 * @FilePath: \common\infra\common\error.go * @Description: 公共错误信息定义 * * Copyright (c) 2022 by 洪流, All Rights Reserved.
* @Author: hongliu * @Date: 2022-09-21 15:46:30 * @LastEditors: hongliu * @LastEditTime: 2022-12-20 16:54:53 * @FilePath: \common\infra\common\infra.go * @Description:基础设施接口定义 * * Copyright (c) 2022 by 洪流, All Rights Reserved.
* @Author: hongliu * @Date: 2022-09-21 15:58:54 * @LastEditors: hongliu * @LastEditTime: 2023-07-17 09:23:29 * @FilePath: \common\infra\common\orm.go * @Description:Orm基础设施接口定义 * * Copyright (c) 2022 by 洪流, All Rights Reserved.
Index ¶
- Variables
- func BuildCountSqlByParams(tableName string, filters []FilterParam) (string, []interface{}, error)
- func BuildQueryPageSqlByParams(tableName string, filters []FilterParam, sorts []SortParm, ...) (string, []interface{}, error)
- func BuildQuerySqlByParams(tableName string, filters []FilterParam, sorts []SortParm) (string, []interface{}, error)
- func DecodeConfig(configValue, structPointer interface{}) error
- type ConfigEvent
- type ConfigEventListenResult
- type ConfigEventTye
- type ConfigImpl
- type ConfigSource
- type ConfigSourceType
- type EventBus
- type EventBusInfra
- type FilterParam
- type Infra
- type Job
- type JobInfra
- type LoginType
- type Orm
- type OrmInfra
- type OrmInfraInstance
- type Oss
- type OssInfra
- type Redis
- type RedisInfra
- type Session
- type SessionManager
- type SessionManagerInfra
- type SortParm
- type UserData
Constants ¶
This section is empty.
Variables ¶
var ( ErrReceiveEventTimeout = errors.New("接收事件出现超时") ErrReceiveDataTimeout = errors.New("接收数据出现超时") ErrAdvanceExit = errors.New("提前退出") )
"自定义错误"相关定义
Functions ¶
func BuildCountSqlByParams ¶
func BuildCountSqlByParams(tableName string, filters []FilterParam) (string, []interface{}, error)
BuildCountSqlByParams 根据参数创建统计语句和查询列表
func BuildQueryPageSqlByParams ¶ added in v0.0.17
func BuildQueryPageSqlByParams(tableName string, filters []FilterParam, sorts []SortParm, currentPage, pageSize uint) (string, []interface{}, error)
BuildQueryPageSqlByParams 通过参数创建分页查询语句和参数列表
func BuildQuerySqlByParams ¶
func BuildQuerySqlByParams(tableName string, filters []FilterParam, sorts []SortParm) (string, []interface{}, error)
BuildQuerySqlByParams 根据参数创建查询语句和参数列表
func DecodeConfig ¶
func DecodeConfig(configValue, structPointer interface{}) error
DecodeConfig 反序列化配置信息,并返回详细的错误列表
Types ¶
type ConfigEventListenResult ¶
type ConfigEventListenResult struct { ConfigEvent ConfigEvent // 配置事件 Error error // 错误 }
ConfigEventListenResult 配置事件监听结果
type ConfigEventTye ¶
type ConfigEventTye string
ConfigEventTye 配置事件类型
const (
ConfigChanged ConfigEventTye = "configChanged" // 配置发生变化
)
配置事件类型相关定义
type ConfigImpl ¶
type ConfigImpl interface {
Listen(context.Context, time.Duration) <-chan ConfigEventListenResult
}
ConfigImpl 配置信息接口定义
type ConfigSource ¶
type ConfigSource interface { // 初始化接口需要传入服务名称和配置数据源的访问端点信息 Init(ctx context.Context) error // 初始化配置数据源 // 所有数据源方案通过兼容"文件名称"这样的单层概念进行数据存储 // 文件名称通过"."进行模块划分,从而实现服务级别的唯一性,例如:infra.oss.yaml、adapter.openapi.yaml // 即文件名称的命名结构具有了分层的功能,所有数据源方案只需要实现单层存储即可,例如如下场景: // Apollo可以将每个"文件名称"按照命名空间的方案进行存储和读取 // K8s可以以"文件名称"来命名ConfigMap的名称进行存储和读取 // 本地配置文件存储配置文件可以按照"文件名称"为名的形式存放在本地config目录下 Read(filename string, value interface{}, timeout time.Duration) error // 读取指定文件名称的配置数据【带超时控制】 Listen(filename string, value interface{}, timeout time.Duration) error // 监听指定文件的配置数据更新,配置更新时立即访问最新数据,否则超市推出该监听接口 }
ConfigSource 配置数据源抽象接口定义
type ConfigSourceType ¶
type ConfigSourceType string
ConfigSourceType 配置数据源类型
const ( Apollo ConfigSourceType = "apollo" // Apollo配置中心 K8s ConfigSourceType = "k8s" // K8s ConfigMap存储方法 Local ConfigSourceType = "local" // 配置文件本地存储 )
配置数据源相关定义
type EventBus ¶
type EventBus interface { Subscribe(topic string, subscriber string, fn interface{}) error // 订阅主题,"subscriber"参数会表明本次订阅者的身份 Unsubscribe(topic string, subscriber string) error // 取消已经订阅的单个主题,需要表明订阅者身份 Publish(topic string, args ...interface{}) error // 发布事件到总线 PublishWithReply(topic string, timeout time.Duration, args ...interface{}) (interface{}, error) // 目前只支持返回一个结果和err信息函数的handler }
EventBus 事件总线接口定义
type EventBusInfra ¶
EventBusInfra event_bus基础设施接口定义
type FilterParam ¶
type FilterParam struct { Name string // 筛选参数名称 Values []string // 筛选参数值列表 Operator string // 筛选条件操作 }
FilterParam 筛选参数
type Infra ¶
type Infra interface { Start(ctx context.Context) error // 启动基础设施 Stop() error // 关闭基础设施 Restart(ctx context.Context) error // 重启基础设施 Name() string // 基础设施名称 }
Infra 基础设施接口定义
type Orm ¶
type Orm interface { DB(databaseName ...string) (orm Orm, err error) // 通过库名称获取数据库连接 Table(table string) (orm Orm, err error) // 切换数据表 Get(dest interface{}, query string, args ...interface{}) error // 查询单个数据 Select(dest interface{}, query string, args ...interface{}) error // 查询多个数据 Insert(value interface{}) (uint64, error) // 插入单个数据 BatchInsert(values interface{}) error // 批量插入 Update(condition string, updateValue map[string]interface{}) error // 更新数据 Delete(condition string, args ...interface{}) error // 删除数据 Exec(query string, args ...interface{}) error // 执行原生sql Begin() error // 开启事务 Commit() error // 执行事务 }
Orm Orm基础设施接口定义
type OrmInfraInstance ¶ added in v1.0.4
OrmInfraInstance Orm基础设施纯接口实例
type Oss ¶
type Oss interface { Publish(ctx context.Context, sourcePath string, destPath string) error // 向oss发布文件,sourcePath为本地文件路径,destPath为目标路径 PublishFromReader(ctx context.Context, filename string, reader io.Reader) (string, error) // 从缓存向oss发布文件 Copy(ctx context.Context, sourcePath string, destPath string) error // 在oss中复制文件 Get(ctx context.Context, filePath string) ([]byte, error) // 从oss下载文件 ConstructTemporarySignatureUrl(ctx context.Context, originUrl string) (string, error) // 构建临时签名Url ConstructTemporarySignatureUrls(ctx context.Context, urlMap map[uint]string) (map[uint]string, error) // 批量构建临时签名Url GetOriginUrl(ctx context.Context, url string) (string, error) // 获取原始的url }
Oss 对象存储通用接口定义
type Redis ¶
type Redis interface { Set(key string, value interface{}, expiration time.Duration) error // 设置单个字符串数据 Get(key string) (string, error) // 读取单个字符串数据 ReadAllKeys(match string) ([]string, error) // 读取所有的key Delete(key string) error // 删除 SetNX(key string, value interface{}, expiration time.Duration) (bool, error) // 单个键值数据不存在时设置 }
Redis Redis接口定义
type Session ¶ added in v1.0.3
type Session struct { ID string // 会话ID AccountID uint // 账号ID LoginType LoginType // 登录类型 IP string // 登录IP地址 LastOperateTime *time.Time // 最近操作时间 }
Session 会话信息
type SessionManager ¶ added in v1.0.3
type SessionManager interface { HasUser(userID string) bool // 用户是否存在 HasUserSession(userID, sessionID string) bool // 用户会话是否存在 GetUserSession(userID, sessionID string) (*Session, error) // 获取用户会话 AddUserData(userData interface{}) error // 新增在线用户 AddUserSession(userID string, session *Session) error // 新增在线用户会话 RemoveUserData(userID string) // 删除一个在线用户 RemoveUserSession(userID, sessionID string) // 移除在线用户会话 UpdateUserSessionTime(userID, session string, time *time.Time) error // 更新在线用户 Clear() // 清空全部用户 }
SessionManager 会话管理器
type SessionManagerInfra ¶ added in v1.0.3
type SessionManagerInfra interface { SessionManager Infra }
SessionManagerInfra 会话管理器基础设施
type UserData ¶ added in v1.0.3
type UserData interface { GetUserID() string // 获取用户ID GetSession(sessionID string) *Session // 获取会话 GetSessions() []*Session // 获取全部会话 AddSession(session *Session) error // 新增会话 RemoveSession(sessionID string) // 移除会话 UpdateSession(session *Session) error // 更新会话 }
UserData 用户信息