duolasdk

package module
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: 2 Imported by: 0

README

Duola SDK

Duola SDK 是一个功能丰富的桌面应用程序开发工具包,为 Duola 桌面应用程序提供核心功能支持。

功能特性

🗃️ 多模式数据存储
  • 持久化存储: 基于 SQLite 的本地存储,数据持久化保存
  • 内存存储: 高性能内存存储,适用于临时数据
  • Redis 风格 API: 支持 Key-Value、Hash、List、Set 等多种数据结构
  • 过期机制: 支持键值过期自动清理
  • SQL 接口: 提供原生 SQL 执行接口,满足复杂查询需求
🌐 网络通信
  • HTTP 客户端: 功能完整的 HTTP 客户端实现
  • Cookie 管理: 自动管理会话状态
  • 拦截器支持: 支持请求和响应拦截器
  • 多种数据格式: 支持 JSON、表单等数据发送
  • 验证码支持: 内置验证码图片获取功能
📝 统一日志
  • 多级别日志: 支持 DEBUG、INFO、WARN、ERROR 等日志级别
  • 多输出方式: 支持文件和控制台输出
  • 自定义格式: 支持自定义日志格式
  • 线程安全: 线程安全的日志记录实现
🔧 其他能力
  • AI 能力: 集成人工智能相关功能接口
  • 支付支持: 提供支付功能接口
  • 系统接口: 提供操作系统级功能访问
  • 发布工具: 提供应用打包发布功能

安装

go get github.com/16chusi/duolasdk

快速开始

初始化存储
import (
    "github.com/16chusi/duolasdk"
    "github.com/16chusi/duolasdk/core"
)

// 创建日志实例
logs := core.NewLogger(&core.LoggerOption{
    Level: "debug",
})

// 创建存储实例
store := duolasdk.NewStore(core.StoreOption{
    Logger: logs,
    FilePath: "/path/to/store",  // 存储文件路径
    FileName: "mydata.db",       // 存储文件名
})
使用 KV 存储
// 设置键值
err := store.Set("username", "Alice", true)  // true 表示持久化存储
if err != nil {
    logs.Error("设置键值失败:", err)
}

// 获取键值
value, err := store.Get("username", true)
if err != nil {
    logs.Error("获取键值失败:", err)
} else {
    logs.Info("用户名:", value)
}

// 删除键值
err = store.Delete("username", true)
if err != nil {
    logs.Error("删除键值失败:", err)
}
使用 Redis 风格数据结构
// Hash 操作
err = store.HSet("user:1001", "name", "Alice", true)
err = store.HSet("user:1001", "email", "alice@example.com", true)

name, _ := store.HGet("user:1001", "name", true)
userMap, _ := store.HGetAll("user:1001", true)

// List 操作
err = store.LPush("tasks", "task1", "task2", true)
err = store.RPush("tasks", "task3", true)

length, _ := store.LLen("tasks", true)
tasks, _ := store.LRange("tasks", 0, -1, true)

// Set 操作
err = store.SAdd("tags", "go", "sdk", "duola", true)
tags, _ := store.SMembers("tags", true)
网络请求
// 创建 HTTP 客户端
httpCli := core.NewHttp(logs)

// GET 请求
response, err := httpCli.Get("https://api.example.com/users", core.Options{
    Query: map[string]string{
        "page": "1",
        "size": "10",
    },
})

// POST 请求 (JSON)
response, err := httpCli.Post("https://api.example.com/users", core.Options{
    Headers: map[string]string{
        "Content-Type": "application/json",
    },
    Body: map[string]interface{}{
        "name": "Alice",
        "age":  30,
    },
})

文档

详细文档请查看 开发说明文档

许可证

MIT License

联系方式

如有问题,请提交 Issue 或联系开发团队。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppStore

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

AppStore 实现 IStore 接口,支持持久化和内存存储

func NewStore

func NewStore(opts ...core.StoreOption) *AppStore

NewStore 创建并初始化 AppStore 实例

func (*AppStore) Close

func (s *AppStore) Close() error

Close closes the storage connection.

func (*AppStore) CreateTable

func (s *AppStore) CreateTable(tableName string, schema string) error

func (*AppStore) CreateTableMem

func (s *AppStore) CreateTableMem(tableName string, schema string) error

func (*AppStore) Delete

func (s *AppStore) Delete(key string, persistent ...bool) error

Delete removes a key.

func (*AppStore) DropTable

func (s *AppStore) DropTable(tableName string) error

func (*AppStore) DropTableMem

func (s *AppStore) DropTableMem(tableName string) error

func (*AppStore) Exec

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

Exec executes a query without returning any rows.

func (*AppStore) ExecMem

func (s *AppStore) ExecMem(query string, args ...interface{}) (sql.Result, error)

ExecMem executes a query without returning any rows in memory.

func (*AppStore) Expire

func (s *AppStore) Expire(key string, milliseconds int64, persistent ...bool) error

Expire sets an expiration for a key.

func (*AppStore) Get

func (s *AppStore) Get(key string, persistent ...bool) (string, error)

Get retrieves the value for a key.

func (*AppStore) GetStore

func (s *AppStore) GetStore(persistent ...bool) core.IStore

GetStore 根据 persistent 参数选择存储实例

func (*AppStore) HDel

func (s *AppStore) HDel(key string, fields ...string) error

HDel deletes one or more fields from a hash.

func (*AppStore) HDelMem

func (s *AppStore) HDelMem(key string, fields ...string) error

HDelMem deletes one or more fields from a hash in memory.

func (*AppStore) HExists

func (s *AppStore) HExists(key, field string, persistent ...bool) (bool, error)

HExists checks if a field exists in a hash.

func (*AppStore) HGet

func (s *AppStore) HGet(key, field string, persistent ...bool) (string, error)

HGet gets the value of a field in a hash.

func (*AppStore) HGetAll

func (s *AppStore) HGetAll(key string, persistent ...bool) (map[string]string, error)

HGetAll gets all fields and values in a hash.

func (*AppStore) HKeys

func (s *AppStore) HKeys(key string, persistent ...bool) ([]string, error)

HKeys gets all the fields in a hash.

func (*AppStore) HLen

func (s *AppStore) HLen(key string, persistent ...bool) (int, error)

HLen gets the number of fields in a hash.

func (*AppStore) HMGet

func (s *AppStore) HMGet(key string, fields ...string) ([]string, error)

HMGet gets the values of multiple fields in a hash.

func (*AppStore) HMGetMem

func (s *AppStore) HMGetMem(key string, fields ...string) ([]string, error)

HMGetMem gets the values of multiple fields in a hash from memory.

func (*AppStore) HMSet

func (s *AppStore) HMSet(key string, fieldValue map[string]string, persistent ...bool) error

HMSet sets the values of multiple fields in a hash.

func (*AppStore) HSet

func (s *AppStore) HSet(key, field, value string, persistent ...bool) error

HSet sets the value of a field in a hash.

func (*AppStore) LLen

func (s *AppStore) LLen(key string, persistent ...bool) (int, error)

LLen gets the length of a list.

func (*AppStore) LPop

func (s *AppStore) LPop(key string, persistent ...bool) (string, error)

LPop removes and returns the first element of a list.

func (*AppStore) LPush

func (s *AppStore) LPush(key string, values ...string) error

LPush prepends one or multiple values to a list.

func (*AppStore) LPushMem

func (s *AppStore) LPushMem(key string, values ...string) error

LPushMem prepends one or multiple values to a list in memory.

func (*AppStore) LRange

func (s *AppStore) LRange(key string, start, stop int, persistent ...bool) ([]string, error)

LRange returns a range of elements from a list.

func (*AppStore) List

func (s *AppStore) List(persistent ...bool) (map[string]string, error)

List lists all key-value pairs.

func (*AppStore) Query

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

Query executes a query that returns rows.

func (*AppStore) QueryMem

func (s *AppStore) QueryMem(query string, args ...interface{}) (*sql.Rows, error)

QueryMem executes a query that returns rows in memory.

func (*AppStore) QueryRow

func (s *AppStore) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow executes a query that is expected to return at most one row.

func (*AppStore) QueryRowMem

func (s *AppStore) QueryRowMem(query string, args ...interface{}) *sql.Row

QueryRowMem executes a query that is expected to return at most one row in memory.

func (*AppStore) RPop

func (s *AppStore) RPop(key string, persistent ...bool) (string, error)

RPop removes and returns the last element of a list.

func (*AppStore) RPush

func (s *AppStore) RPush(key string, values ...string) error

RPush appends one or multiple values to a list.

func (*AppStore) RPushMem

func (s *AppStore) RPushMem(key string, values ...string) error

RPushMem appends one or multiple values to a list in memory.

func (*AppStore) SAdd

func (s *AppStore) SAdd(key string, members ...string) error

SAdd adds one or more members to a set.

func (*AppStore) SAddMem

func (s *AppStore) SAddMem(key string, members ...string) error

SAddMem adds one or more members to a set in memory.

func (*AppStore) SCard

func (s *AppStore) SCard(key string, persistent ...bool) (int, error)

SCard gets the number of members in a set.

func (*AppStore) SIsMember

func (s *AppStore) SIsMember(key, member string, persistent ...bool) (bool, error)

SIsMember checks if a member is in a set.

func (*AppStore) SMembers

func (s *AppStore) SMembers(key string, persistent ...bool) ([]string, error)

SMembers returns all the members of a set.

func (*AppStore) SRem

func (s *AppStore) SRem(key string, members ...string) error

SRem removes one or more members from a set.

func (*AppStore) SRemMem

func (s *AppStore) SRemMem(key string, members ...string) error

SRemMem removes one or more members from a set in memory.

func (*AppStore) Set

func (s *AppStore) Set(key, value string, persistent ...bool) error

Set stores the key-value pair.

func (*AppStore) TTL

func (s *AppStore) TTL(key string, persistent ...bool) (int64, error)

TTL gets the time-to-live for a key.

func (*AppStore) TableExists

func (s *AppStore) TableExists(tableName string) (bool, error)

func (*AppStore) TableExistsMem

func (s *AppStore) TableExistsMem(tableName string) (bool, error)

Directories

Path Synopsis
ai

Jump to

Keyboard shortcuts

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