Documentation
¶
Index ¶
- Constants
- func Compare(unit1 *ValueUnit, unit2 *ValueUnit) bool
- func Copy(srcValue *ValueUnit, newValue *ValueUnit)
- func Join(src ...string) string
- func Split(src string) []string
- func ToBase[T IValueType](unit *ValueUnit) T
- func ToBaseF[T IValueType](unit *ValueUnit, err error) T
- func UnitToJStruct[T any](unit *ValueUnit) *T
- func UnitToString(unit *ValueUnit) string
- type CfgExt
- func (c *CfgExt) AddParam(param *CfgParam) error
- func (c *CfgExt) Get(keys ...string) (*ValueUnit, error)
- func (c *CfgExt) GetAll() (map[string]ValueUnit, error)
- func (c *CfgExt) GetUser(user string, keys ...string) (*ValueUnit, error)
- func (c *CfgExt) GetWithFilter(prefix, user string) (map[string]ValueUnit, error)
- func (c *CfgExt) Init(core *XStorage) error
- func (c *CfgExt) Set(key string, value string) error
- func (c *CfgExt) SetUser(user, key string, value string) error
- type CfgParam
- type EmptyLogger
- func (e EmptyLogger) Error(ctx context.Context, s string, i ...interface{})
- func (e EmptyLogger) Info(ctx context.Context, s string, i ...interface{})
- func (e EmptyLogger) LogMode(level logger.LogLevel) logger.Interface
- func (e EmptyLogger) Trace(ctx context.Context, begin time.Time, ...)
- func (e EmptyLogger) Warn(ctx context.Context, s string, i ...interface{})
- type ErrStr
- type IDBCore
- type IFileCore
- type IValueType
- type KeyValueModel
- type KeyValueProperty
- type ParamMap
- type SqliteCore
- type TomlCore
- type ValueType
- type ValueUnit
- type WebCode
- type WebFailReason
- type WebPack
- type WebPackSetting
- type XStorage
- func (m *XStorage) Delete(key string) error
- func (m *XStorage) FromDiskGetAll() (map[string]*ValueUnit, error)
- func (m *XStorage) Get(key string) (*ValueUnit, error)
- func (m *XStorage) GetAll() (map[string]*ValueUnit, error)
- func (m *XStorage) GetAndSetDefault(key string, defaultValue *ValueUnit) (*ValueUnit, error)
- func (m *XStorage) GetAndSetDefaultAsync(key string, defaultValue *ValueUnit, rec *ValueUnit) (bool, error, chan error)
- func (m *XStorage) GetAndSetDefaultHP(key string, defaultValue *ValueUnit, rec *ValueUnit) (bool, error)
- func (m *XStorage) GetFromJson(key string, value interface{}) error
- func (m *XStorage) GetHP(key string, valueUnit *ValueUnit) (bool, error)
- func (m *XStorage) Init(setting XStorageSetting) error
- func (m *XStorage) Set(key string, value *ValueUnit) error
- func (m *XStorage) SetAsync(key string, value *ValueUnit) (error, chan error)
- func (m *XStorage) SetDefault(key string, defaultValue *ValueUnit) error
- func (m *XStorage) SetDefaultAsync(key string, defaultValue *ValueUnit) (error, chan error)
- func (m *XStorage) SetToJson(key string, value interface{}) error
- type XStorageSetting
Constants ¶
View Source
const ( DBBegin keyValueSaveType = iota SqlLiteDB FileBegin Toml // 为保证效率,必须开启UseCache、FullInitLoad )
View Source
const ( ValueTypeNormalBegin ValueType = iota ValueTypeString ValueTypeInt ValueTypeFloat ValueTypeBool ValueTypeNormalEnd ValueTypeSliceBegin = 100 ValueTypeSliceString = iota + ValueTypeSliceBegin - ValueTypeNormalEnd - 1 ValueTypeSliceInt ValueTypeSliceFloat ValueTypeSliceBool )
可能会被外部调用,所以复杂命名
View Source
const ( ErrSqliteDBFileAddrEmpty = misc.ErrStr("sqlite db file addr is empty") ErrSqliteDBFileAddrNotExist = misc.ErrStr("sqlite db file addr not exist") ErrMgrNotInit = misc.ErrStr("mgr not init") ErrSqliteCoreNotInit = misc.ErrStr("sqlite core not init") ErrSetValue = misc.ErrStr("set value error") ErrKeyIsEmpty = misc.ErrStr("key is empty") ErrNotUseCache = misc.ErrStr("not use cache") ErrKeyNotExist = misc.ErrStr("key not exist") ErrValueIsNil = misc.ErrStr("value is nil") ErrSliceButValueIntIsNil = misc.ErrStr("slice but ValueInt is nil") ErrValueType = misc.ErrStr("value type error") ErrOpenSqlite = misc.ErrStr("open sqlite error") ErrAutoMigrate = misc.ErrStr("auto migrate error") ErrRecIsNil = misc.ErrStr("rec is nil") ErrNotUseDb = misc.ErrStr("not use db") ErrRecordToMap = misc.ErrStr("record to map error") ErrPoolType = misc.ErrStr("pool type error") ErrNotUseCacheAndNotUseDb = misc.ErrStr("not use cache and not use db") ErrGetAllValue = misc.ErrStr("get all value error") ErrGinEngineRun = misc.ErrStr("gin engine run error") ErrNotUseCacheOrNotUseDbAndFullInitLoad = misc.ErrStr("not use cache or not use db and full init load") ErrUseJsonButNotUseCacheAndNotFullInitLoad = misc.ErrStr("use json, but not use cache and not full init load") ErrNewSqliteCore = misc.ErrStr("new sqlite core error") ErrNotUseDbAndFullInitLoad = misc.ErrStr("not use db and full init load") ErrValueUnitIsNil = misc.ErrStr("valueUnit is nil") ErrValueIsDirty = misc.ErrStr("value is dirty") ErrRemoveFromMap = misc.ErrStr("remove from map error") ErrDeleteValue = misc.ErrStr("delete value error") ErrKeyCanNotContainSquareBrackets = misc.ErrStr("Key can not contain []") ErrSqliteData2Model = misc.ErrStr("sqliteData2Model") ErrCreateValue = misc.ErrStr("create value error") ErrRemoveValue = misc.ErrStr("remove value error") ErrGetSliceValue = misc.ErrStr("get slice value error") ErrsqliteModel2Data = misc.ErrStr("sqliteModel2Data error") ErrGet = misc.ErrStr("get error") )
View Source
const ( ErrNil = ErrStr("nil") ErrValueTypeNotMatch = ErrStr("value type not match") // auto generated from .\sqlite.go ErrCoreIsNil = ErrStr("core is nil") // auto generated from .\cfg_pack.go ErrNotInitialized = ErrStr("not initialized") // auto generated from .\cfg_pack.go ErrKeyNotFound = ErrStr("key not found") // auto generated from .\cfg_pack.go ErrParamIsNil = ErrStr("param is nil") // auto generated from .\cfg_pack.go ErrParamIsInvalid = ErrStr("param is invalid") // auto generated from .\cfg_pack.go ErrKeyAlreadyExist = ErrStr("key already exist") // auto generated from .\cfg_pack.go ErrParamIsEmpty = ErrStr("param is empty") // auto generated from .\cfg_pack.go ErrJsonMarshalErr = ErrStr("json marshal err") // auto generated from .\mgr.go ErrSetValueErr = ErrStr("set value err") // auto generated from .\mgr.go ErrNoData = ErrStr("no data") // auto generated from .\mgr.go ErrJsonUnmarshalErr = ErrStr("json unmarshal err") // auto generated from .\mgr.go )
Variables ¶
This section is empty.
Functions ¶
func ToBase ¶
func ToBase[T IValueType](unit *ValueUnit) T
ToBase 直接转换为基础类型,一方面是为了避免频繁的类型转换,另一方面是为了限制类型
func ToBaseF ¶
func ToBaseF[T IValueType](unit *ValueUnit, err error) T
func UnitToString ¶
Types ¶
type CfgExt ¶
type CfgExt struct {
// contains filtered or unexported fields
}
CfgExt 为xstorage增加一个通用的配置机制
func (*CfgExt) GetWithFilter ¶
type EmptyLogger ¶
type EmptyLogger struct { }
func (EmptyLogger) Error ¶
func (e EmptyLogger) Error(ctx context.Context, s string, i ...interface{})
func (EmptyLogger) Info ¶
func (e EmptyLogger) Info(ctx context.Context, s string, i ...interface{})
type IValueType ¶
type KeyValueModel ¶
type KeyValueProperty ¶
type KeyValueProperty uint32
const ( // MultiSafe 多线程安全,仅针对缓存 MultiSafe KeyValueProperty = 1 << iota // TODO: // UseCache 缓存 UseCache // UseDisk 落盘 UseDisk // FullInitLoad 全量初始化加载,没有的话即懒加载,仅在同时使用缓存和数据库时有效,建议与MultiSafe一起使用,并使用setAsync方法进行set FullInitLoad // OpenWeb 启用web端口,建议不要使用内置的web服务,而是自己启动一个web服务,然后调用GetGinEngine方法获取gin引擎,然后自己注册路由 OpenWeb )
type SqliteCore ¶
func NewSqliteCore ¶
func NewSqliteCore(DbFileAddr string) (*SqliteCore, error)
func (*SqliteCore) Delete ¶
func (m *SqliteCore) Delete(key string) error
type TomlCore ¶
type TomlCore struct {
// contains filtered or unexported fields
}
func NewTomlCore ¶
type ValueUnit ¶
type ValueUnit struct { Type ValueType Data interface{} // contains filtered or unexported fields }
ValueUnit 加入类型,用于在非反射的情况下直接处理类型
func JStructToUnit ¶
func StringToUnit ¶
StringToUnit 将json字符串转为ValueUnit
func ToUnit ¶
func ToUnit[T IValueType](value T, valueType ValueType) *ValueUnit
type WebFailReason ¶
type WebFailReason int // web失败原因
const ( WebFailReasonNull WebFailReason = iota WebFailReasonNoLegalParam WebFailReasonInnerError )
type WebPack ¶
WebPack 是xstorage的拓展之一,必须绑定xstorage使用 因为是小众需求所以做一下拆分
func NewWebPack ¶
func NewWebPack(setting WebPackSetting, core *XStorage) (*WebPack, error)
type XStorage ¶
type XStorage struct {
// contains filtered or unexported fields
}
func NewXStorage ¶
func NewXStorage(setting XStorageSetting) (*XStorage, error)
func (*XStorage) FromDiskGetAll ¶
func (*XStorage) GetAndSetDefault ¶
func (*XStorage) GetAndSetDefaultAsync ¶
func (m *XStorage) GetAndSetDefaultAsync(key string, defaultValue *ValueUnit, rec *ValueUnit) (bool, error, chan error)
GetAndSetDefaultAsync get值,如果没有就设置并返回默认值,返回 是否setdefault数据,数据,错误
func (*XStorage) GetAndSetDefaultHP ¶
func (m *XStorage) GetAndSetDefaultHP(key string, defaultValue *ValueUnit, rec *ValueUnit) (bool, error)
GetAndSetDefaultHP get值,如果没有就设置并返回默认值,返回 是否setdefault数据,数据,错误
func (*XStorage) GetFromJson ¶
func (*XStorage) Init ¶
func (m *XStorage) Init(setting XStorageSetting) error
func (*XStorage) SetDefault ¶
SetDefault 设置默认值,如果已经存在则不设置
func (*XStorage) SetDefaultAsync ¶
SetDefaultAsync 设置默认值,如果已经存在则不设置
type XStorageSetting ¶
type XStorageSetting struct { Property KeyValueProperty SaveType keyValueSaveType DBAddr string FileAddr string }
Click to show internal directories.
Click to hide internal directories.