core

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2025 License: MulanPSL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyNotFound = errors.New("key not found")

ErrKeyNotFound 当在存储中找不到键时返回

Functions

func Version

func Version() string

Types

type AIProvider

type AIProvider interface {
	// Chat 发送聊天消息
	Chat(model string, messages []Message) (string, error)
	// ChatStream 发送聊天消息并流式返回结果
	ChatStream(model string, messages []Message, callback func(string)) error
	// ListModels 获取模型列表
	ListModels() ([]string, error)
	// Validate 验证连接和配置
	Validate() error
}

AIProvider AI提供者接口

type AppLog

type AppLog struct {
	*log.Logger
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(o *LoggerOption) *AppLog

func (*AppLog) WithPrefix

func (l *AppLog) WithPrefix(s string) *AppLog

type ColumnInfo

type ColumnInfo struct {
	Name         string `json:"name"`
	Type         string `json:"type"`
	NotNull      bool   `json:"notNull"`
	DefaultValue string `json:"defaultValue"`
	PrimaryKey   bool   `json:"primaryKey"`
}

ColumnInfo 表示列信息

type Config

type Config struct {
	BaseURL      string
	Headers      map[string]string
	ResponseType string
	Method       string
	HTTPClient   *http.Client
}

Config 用于创建 HttpCli 实例的配置

type HttpCli

type HttpCli struct {
	// contains filtered or unexported fields
}

HttpCli 是我们的 axios 客户端实例

func NewHttp

func NewHttp(log *AppLog) *HttpCli

func (*HttpCli) Create

func (c *HttpCli) Create(cfg *Config) *HttpCli

func (*HttpCli) Delete

func (c *HttpCli) Delete(url string, options Options) (*Response, error)

func (*HttpCli) Do

func (c *HttpCli) Do(method, path string, opt Options) (*Response, error)

func (*HttpCli) DownloadFileWithResume

func (c *HttpCli) DownloadFileWithResume(url string, filepath string, progressCallback func(int64, int64)) error

DownloadFileWithResume 支持断点续传的文件下载方法

func (*HttpCli) Get

func (c *HttpCli) Get(url string, options Options) (*Response, error)

func (*HttpCli) GetCaptchaImage

func (c *HttpCli) GetCaptchaImage(path string) (string, error)

func (*HttpCli) Head

func (c *HttpCli) Head(url string, options Options) (*Response, error)

func (*HttpCli) Options

func (c *HttpCli) Options(url string, options Options) (*Response, error)

func (*HttpCli) Patch

func (c *HttpCli) Patch(url string, options Options) (*Response, error)

func (*HttpCli) Post

func (c *HttpCli) Post(url string, options Options) (*Response, error)

func (*HttpCli) PostStream

func (c *HttpCli) PostStream(path string, options Options) (*http.Response, error)

PostStream 发送 POST 请求并返回原始的 http.Response 用于流式处理

func (*HttpCli) Put

func (c *HttpCli) Put(url string, options Options) (*Response, error)

func (*HttpCli) UseRequestInterceptor

func (c *HttpCli) UseRequestInterceptor(interceptors ...RequestInterceptor)

func (*HttpCli) UseResponseInterceptor

func (c *HttpCli) UseResponseInterceptor(interceptors ...ResponseInterceptor)

type IStore

type IStore interface {
	// KeyValue operations
	Set(key, value string) error
	Get(key string) (string, error)
	Delete(key string) error
	List() (map[string]string, error)

	// Expiration operations
	Expire(key string, milliseconds int64) error
	TTL(key string) (int64, error)

	// Hash operations (like redis)
	HSet(key, field, value string) error
	HGet(key, field string) (string, error)
	HGetAll(key string) (map[string]string, error)
	HMGet(key string, fields ...string) ([]string, error)
	HMSet(key string, fieldValue map[string]string) error
	HDel(key string, fields ...string) error
	HExists(key, field string) (bool, error)
	HKeys(key string) ([]string, error)
	HLen(key string) (int, error)

	// List operations (like redis)
	LPush(key string, values ...string) error
	RPush(key string, values ...string) error
	LPop(key string) (string, error)
	RPop(key string) (string, error)
	LRange(key string, start, stop int) ([]string, error)
	LLen(key string) (int, error)

	// Set operations (like redis)
	SAdd(key string, members ...string) error
	SRem(key string, members ...string) error
	SMembers(key string) ([]string, error)
	SIsMember(key, member string) (bool, error)
	SCard(key string) (int, error)

	// SQL operations
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row

	// Enhanced SQL operations for table management
	CreateTable(tableName string, schema string) error
	TableExists(tableName string) (bool, error)
	DropTable(tableName string) error
	AddColumn(tableName, columnDef string) error
	GetTableSchema(tableName string) ([]ColumnInfo, error)
	BeginTx() (ITransaction, error)

	// Close 关闭存储连接
	Close() error
}

IStore 定义存储接口

type ITransaction

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

ITransaction 事务接口

type LocalStore

type LocalStore struct {
	// contains filtered or unexported fields
}

LocalStore 本地存储

func NewLocalStore

func NewLocalStore(opts ...StoreOption) (*LocalStore, error)

NewLocalStore 创建一个新的本地存储实例

func (*LocalStore) AddColumn

func (l *LocalStore) AddColumn(tableName, columnDef string) error

AddColumn 添加列

func (*LocalStore) BeginTx

func (l *LocalStore) BeginTx() (ITransaction, error)

BeginTx 开始事务

func (*LocalStore) Close

func (l *LocalStore) Close() error

Close 关闭本地存储连接

func (*LocalStore) CreateTable

func (l *LocalStore) CreateTable(tableName string, schema string) error

CreateTable 创建表

func (*LocalStore) Delete

func (l *LocalStore) Delete(key string) error

Delete 从本地存储中删除键值对

func (*LocalStore) DropTable

func (l *LocalStore) DropTable(tableName string) error

DropTable 删除表

func (*LocalStore) Exec

func (l *LocalStore) Exec(query string, args ...interface{}) (sql.Result, error)

Exec 在本地存储上执行 SQL 语句

func (*LocalStore) Expire

func (l *LocalStore) Expire(key string, milliseconds int64) error

Expire 设置键的过期时间(毫秒)

func (*LocalStore) Get

func (l *LocalStore) Get(key string) (string, error)

Get 从本地存储中获取值

func (*LocalStore) GetTableSchema

func (l *LocalStore) GetTableSchema(tableName string) ([]ColumnInfo, error)

GetTableSchema 获取表结构信息

func (*LocalStore) HDel

func (l *LocalStore) HDel(key string, fields ...string) error

HDel 删除哈希表key中的一个或多个字段

func (*LocalStore) HExists

func (l *LocalStore) HExists(key, field string) (bool, error)

HExists 检查哈希表key中是否存在字段field

func (*LocalStore) HGet

func (l *LocalStore) HGet(key, field string) (string, error)

HGet 获取哈希表key中字段field的值

func (*LocalStore) HGetAll

func (l *LocalStore) HGetAll(key string) (map[string]string, error)

HGetAll 获取哈希表key中所有的字段和值

func (*LocalStore) HKeys

func (l *LocalStore) HKeys(key string) ([]string, error)

HKeys 获取哈希表key中的所有字段名

func (*LocalStore) HLen

func (l *LocalStore) HLen(key string) (int, error)

HLen 获取哈希表key中字段的数量

func (*LocalStore) HMGet

func (l *LocalStore) HMGet(key string, fields ...string) ([]string, error)

HMGet 获取哈希表key中一个或多个字段的值

func (*LocalStore) HMSet

func (l *LocalStore) HMSet(key string, fieldValue map[string]string) error

HMSet 同时设置哈希表key中一个或多个字段的值

func (*LocalStore) HSet

func (l *LocalStore) HSet(key, field, value string) error

HSet 设置哈希表key中字段field的值

func (*LocalStore) LLen

func (l *LocalStore) LLen(key string) (int, error)

LLen 返回列表key的长度

func (*LocalStore) LPop

func (l *LocalStore) LPop(key string) (string, error)

LPop 移除并返回列表key的头元素

func (*LocalStore) LPush

func (l *LocalStore) LPush(key string, values ...string) error

LPush 将一个或多个值插入到列表key的表头

func (*LocalStore) LRange

func (l *LocalStore) LRange(key string, start, stop int) ([]string, error)

LRange 返回列表key中指定区间内的元素

func (*LocalStore) List

func (l *LocalStore) List() (map[string]string, error)

List 列出本地存储中的所有键值对

func (*LocalStore) Query

func (l *LocalStore) Query(query string, args ...interface{}) (*sql.Rows, error)

Query 在本地存储上执行查询

func (*LocalStore) QueryRow

func (l *LocalStore) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow 在本地存储上执行单行查询

func (*LocalStore) RPop

func (l *LocalStore) RPop(key string) (string, error)

RPop 移除并返回列表key的尾元素

func (*LocalStore) RPush

func (l *LocalStore) RPush(key string, values ...string) error

RPush 将一个或多个值插入到列表key的表尾

func (*LocalStore) SAdd

func (l *LocalStore) SAdd(key string, members ...string) error

SAdd 将一个或多个成员加入到集合key中

func (*LocalStore) SCard

func (l *LocalStore) SCard(key string) (int, error)

SCard 返回集合key的基数(集合中元素的数量)

func (*LocalStore) SIsMember

func (l *LocalStore) SIsMember(key, member string) (bool, error)

SIsMember 判断member是否是集合key的成员

func (*LocalStore) SMembers

func (l *LocalStore) SMembers(key string) ([]string, error)

SMembers 返回集合key中的所有成员

func (*LocalStore) SRem

func (l *LocalStore) SRem(key string, members ...string) error

SRem 从集合key中移除一个或多个成员

func (*LocalStore) Set

func (l *LocalStore) Set(key, value string) error

Set 在本地存储中设置键值对

func (*LocalStore) TTL

func (l *LocalStore) TTL(key string) (int64, error)

TTL 获取键的剩余生存时间(毫秒)

func (*LocalStore) TableExists

func (l *LocalStore) TableExists(tableName string) (bool, error)

TableExists 检查表是否存在

type LoggerOption

type LoggerOption struct {
	Type     string // "file" or "console"
	FileName string // 日志文件路径 if type is "file"
	Level    string
	Prefix   string
}

type MemStore

type MemStore struct {
	// contains filtered or unexported fields
}

MemStore 内存存储

func NewMemStore

func NewMemStore(opts ...StoreOption) (*MemStore, error)

NewMemStore 创建一个新的内存存储实例

func (*MemStore) AddColumn

func (m *MemStore) AddColumn(tableName, columnDef string) error

AddColumn 添加列

func (*MemStore) BeginTx

func (m *MemStore) BeginTx() (ITransaction, error)

BeginTx 开始事务

func (*MemStore) Close

func (m *MemStore) Close() error

Close 关闭内存存储连接

func (*MemStore) CreateTable

func (m *MemStore) CreateTable(tableName string, schema string) error

CreateTable 创建表

func (*MemStore) Delete

func (m *MemStore) Delete(key string) error

Delete 从内存存储中删除键值对

func (*MemStore) DropTable

func (m *MemStore) DropTable(tableName string) error

DropTable 删除表

func (*MemStore) Exec

func (m *MemStore) Exec(query string, args ...interface{}) (sql.Result, error)

Exec 在内存存储上执行 SQL 语句

func (*MemStore) Expire

func (m *MemStore) Expire(key string, milliseconds int64) error

Expire 设置键的过期时间(毫秒)

func (*MemStore) Get

func (m *MemStore) Get(key string) (string, error)

Get 从内存存储中获取值

func (*MemStore) GetTableSchema

func (m *MemStore) GetTableSchema(tableName string) ([]ColumnInfo, error)

GetTableSchema 获取表结构信息

func (*MemStore) HDel

func (m *MemStore) HDel(key string, fields ...string) error

HDel 删除哈希表key中的一个或多个字段

func (*MemStore) HExists

func (m *MemStore) HExists(key, field string) (bool, error)

HExists 检查哈希表key中是否存在字段field

func (*MemStore) HGet

func (m *MemStore) HGet(key, field string) (string, error)

HGet 获取哈希表key中字段field的值

func (*MemStore) HGetAll

func (m *MemStore) HGetAll(key string) (map[string]string, error)

HGetAll 获取哈希表key中所有的字段和值

func (*MemStore) HKeys

func (m *MemStore) HKeys(key string) ([]string, error)

HKeys 获取哈希表key中的所有字段名

func (*MemStore) HLen

func (m *MemStore) HLen(key string) (int, error)

HLen 获取哈希表key中字段的数量

func (*MemStore) HMGet

func (m *MemStore) HMGet(key string, fields ...string) ([]string, error)

HMGet 获取哈希表key中一个或多个字段的值

func (*MemStore) HMSet

func (m *MemStore) HMSet(key string, fieldValue map[string]string) error

HMSet 同时设置哈希表key中一个或多个字段的值

func (*MemStore) HSet

func (m *MemStore) HSet(key, field, value string) error

HSet 设置哈希表key中字段field的值

func (*MemStore) LLen

func (m *MemStore) LLen(key string) (int, error)

LLen 返回列表key的长度

func (*MemStore) LPop

func (m *MemStore) LPop(key string) (string, error)

LPop 移除并返回列表key的头元素

func (*MemStore) LPush

func (m *MemStore) LPush(key string, values ...string) error

LPush 将一个或多个值插入到列表key的表头

func (*MemStore) LRange

func (m *MemStore) LRange(key string, start, stop int) ([]string, error)

LRange 返回列表key中指定区间内的元素

func (*MemStore) List

func (m *MemStore) List() (map[string]string, error)

List 列出内存存储中的所有键值对

func (*MemStore) Query

func (m *MemStore) Query(query string, args ...interface{}) (*sql.Rows, error)

Query 在内存存储上执行查询

func (*MemStore) QueryRow

func (m *MemStore) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow 在内存存储上执行单行查询

func (*MemStore) RPop

func (m *MemStore) RPop(key string) (string, error)

RPop 移除并返回列表key的尾元素

func (*MemStore) RPush

func (m *MemStore) RPush(key string, values ...string) error

RPush 将一个或多个值插入到列表key的表尾

func (*MemStore) SAdd

func (m *MemStore) SAdd(key string, members ...string) error

SAdd 将一个或多个成员加入到集合key中

func (*MemStore) SCard

func (m *MemStore) SCard(key string) (int, error)

SCard 返回集合key的基数(集合中元素的数量)

func (*MemStore) SIsMember

func (m *MemStore) SIsMember(key, member string) (bool, error)

SIsMember 判断member是否是集合key的成员

func (*MemStore) SMembers

func (m *MemStore) SMembers(key string) ([]string, error)

SMembers 返回集合key中的所有成员

func (*MemStore) SRem

func (m *MemStore) SRem(key string, members ...string) error

SRem 从集合key中移除一个或多个成员

func (*MemStore) Set

func (m *MemStore) Set(key, value string) error

Set 在内存存储中设置键值对

func (*MemStore) TTL

func (m *MemStore) TTL(key string) (int64, error)

TTL 获取键的剩余生存时间(毫秒)

func (*MemStore) TableExists

func (m *MemStore) TableExists(tableName string) (bool, error)

TableExists 检查表是否存在

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

Message 聊天消息结构

type Options

type Options struct {
	Headers map[string]string
	Query   map[string]string
	Body    interface{}
}

type RequestInterceptor

type RequestInterceptor func(req *http.Request) error

RequestInterceptor 请求拦截器函数类型

type Response

type Response struct {
	StatusCode int
	Header     http.Header
	Body       string
}

Response 是对 http.Response 的封装

type ResponseInterceptor

type ResponseInterceptor func(res *Response) error

ResponseInterceptor 响应拦截器函数类型

type StoreOption

type StoreOption struct {
	// FilePath 文件保存路径(默认程序运行路径)
	FilePath string
	// FileName 文件保存名称(默认duola.dat)
	FileName string
	// Logger 日志记录器
	Logger *AppLog
	// InitSQL 启动时执行的初始化SQL语句
	InitSQL []string
	// MaxOpenConns 设置最大打开连接数
	MaxOpenConns int
	// MaxIdleConns 设置最大空闲连接数
	MaxIdleConns int
	// OnKeyExpired 当key过期时的回调函数
	OnKeyExpired func(key, value string)
}

StoreOption 存储配置选项

type Transaction

type Transaction struct {
	// contains filtered or unexported fields
}

Transaction 事务实现

func (*Transaction) Commit

func (t *Transaction) Commit() error

Commit 提交事务

func (*Transaction) Exec

func (t *Transaction) Exec(query string, args ...interface{}) (sql.Result, error)

Exec 在事务中执行SQL

func (*Transaction) Query

func (t *Transaction) Query(query string, args ...interface{}) (*sql.Rows, error)

Query 在事务中执行查询

func (*Transaction) QueryRow

func (t *Transaction) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow 在事务中执行单行查询

func (*Transaction) Rollback

func (t *Transaction) Rollback() error

Rollback 回滚事务

type WailsLog

type WailsLog struct {
	// contains filtered or unexported fields
}

func NewWailsLog

func NewWailsLog(appLog *AppLog) *WailsLog

NewWailsLog 创建一个新的 WailsLog 实例

func (*WailsLog) Debug

func (w *WailsLog) Debug(message string)

func (*WailsLog) Error

func (w *WailsLog) Error(message string)

func (*WailsLog) Fatal

func (w *WailsLog) Fatal(message string)

func (*WailsLog) Info

func (w *WailsLog) Info(message string)

func (*WailsLog) Print

func (w *WailsLog) Print(message string)

func (*WailsLog) Trace

func (w *WailsLog) Trace(message string)

func (*WailsLog) Warning

func (w *WailsLog) Warning(message string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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