xgodbconfig

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: BSD-3-Clause-Clear Imports: 7 Imported by: 0

Documentation

Overview

数据库配置的读写支持

Index

Constants

This section is empty.

Variables

View Source
var NOEDIT = errors.New("配置项修改条数无变化")

无变化的错误项

View Source
var NOTFOND error = errors.New("配置项不存在")

未找到的错误项

Functions

func GetBool

func GetBool(name string) bool

获取开关值

name	要获取的配置项的配置下标

func GetFloat

func GetFloat(name string) float64

获取浮点数值

name	要获取的配置项的配置下标

func GetInt

func GetInt(name string) int64

读取配置项的值

name	要获取的配置项的配置下标

func GetSelect

func GetSelect(name string) string

获取select下拉列表

name	要获取的配置项的配置下标

func GetString

func GetString(name string) string

获取string值的配置

name	要获取的配置项的配置下标

func GetUsedPrefix added in v0.2.67

func GetUsedPrefix() map[string]string

获取系统占用的配置项标识

func GetUserConfig added in v0.1.11

func GetUserConfig(uid uint, conf any) error

获取个人配置项

uid		用户ID
conf	配置项(采用json读取的方式进行反向解析,所以此处请使用指针进行获取)

func GroupInserts added in v0.1.11

func GroupInserts(g []ConfigureGroup) error

插入配置项分组信息[一定要指定ID,此处不进行ID自增和ID返回操作,需要手动指定配置组的ID,以便进行无限分类获取]

g	待插入的分组列表信息

func InsertsOrContinue added in v0.0.10

func InsertsOrContinue(confs []Configure) error

设置配置项(批量插入),若存在则跳过该配置项

confs	待插入的配置项列表

func Listen added in v0.2.23

func Listen(name string, fun func(n string))

追加变量变更通知函数

name	监听的配置项名称
fun		执行的回调名称

func Listens added in v0.2.23

func Listens(name []string, fun func(n string))

追加变量变更通知函数-多变量添加

name	监听配置项名称
fun		执行回调的名称

func Regedit added in v0.0.17

func Regedit(c *Config)

注入配置项

func Set added in v0.2.67

func Set(c *ConfigureUsers) error

设置配置项的值

c	配置项的信息,需要有name和type、valuexxx

func SetBool added in v0.0.3

func SetBool(name string, val bool) error

设置bool类型配置

name	配置项的名称
val		配置项的值

func SetFloat added in v0.0.3

func SetFloat(name string, val float64) error

设置float类型配置

name	配置项的名称
val		配置项的值

func SetInt added in v0.0.3

func SetInt(name string, val int64) error

设置int类型配置

name	配置项的名称
val		配置项的值

func SetLongText added in v0.0.3

func SetLongText(name, val string) error

设置longtext类型配置 下拉列表,多项使用,分割key和key_cn使用:分割

name	配置项的名称
val		配置项的值

func SetSelect added in v0.0.3

func SetSelect(name, val string) error

设置select类型配置 下拉列表,多项使用,分割key和key_cn使用:分割

name	配置项的名称
val		配置项的值

func SetString added in v0.0.3

func SetString(name, val string) error

设置string类型配置

name	配置项的名称
val		配置项的值

func SetText added in v0.0.3

func SetText(name, val string) error

设置text类型配置 下拉列表,多项使用,分割key和key_cn使用:分割

name	配置项的名称
val		配置项的值

func SetUserConfigure added in v0.1.11

func SetUserConfigure(uid uint, conf any) error

写入个人配置项

uid		用户ID
conf	配置项(采用json读取的方式进行反向解析,所以此处请使用指针进行获取)

Types

type Config

type Config struct {
	DB                  *gorm.DB
	ConfigTable         string                  // 配置表名称
	ConfigUserTable     string                  // 用户配置存储表
	ConfigureGroupTable string                  // 配置项分组表表明
	ConfigEdit          func(name string) error // 配置项修改的回调函数

	ConfigureUsersTable string            // 配置表名称,参考注册表形式 "A/B": xxxx
	UsedPrefix          map[string]string // 规定占用分组下标及相关释义【仅用于提供说明,不作为实际配置】
	EmptyPath           string            // 空路径时【//或者/结尾时填补的字符】
	CacheUsers          sync.Map
	Cache               sync.Map
	CacheUser           sync.Map
	// contains filtered or unexported fields
}

数据库相关配置

type Configure

type Configure struct {
	Id        uint   `gorm:"column:id;not null;autoIncrement;primaryKey" json:"id" form:"id"`
	NameKey   string `gorm:"column:name_key;type:varchar(100);unique;comment:配置项key" json:"name_key" form:"name_key"`    //配置项key
	NameCn    string `gorm:"column:name_cn;type:varchar(200);comment:配置项名称" json:"name_cn" form:"name_cn"`               //配置项名称
	NameGroup string `gorm:"column:name_group;type:varchar(100);index;comment:配置项组" json:"name_group" form:"name_group"` //配置项组
	Types     string `gorm:"column:types;type:varchar(20);index;comment:配置项类型" json:"types" form:"types"`                //配置项类型
	Desc      string `gorm:"column:desc;type:text;comment:配置项介绍信息" json:"desc" form:"desc"`                              //配置项介绍信息
	ValueBool uint8  ``                                                                                                  // bool类型的值存储 uint8
	/* 138-byte string literal not displayed */
	ValueString string  `gorm:"column:value_string;type:text;comment:字符串类型配置" json:"value_string" form:"value_string"`            // 字符串类型配置
	ValueInt    int64   `gorm:"column:value_int;type:bigint;default:0;comment:int类型配置" json:"value_int,string" form:"value_int"`  // int类型配置
	ValueFloat  float64 `gorm:"column:value_float;type:double;default:0;comment:float类型配置" json:"value_float" form:"value_float"` // float类型配置
	EnumSelect  string  ``                                                                                                        //下拉列表,多项使用,分割key和key_cn使用:分割,下拉选择的值存储在value_string中
	/* 186-byte string literal not displayed */
	CreatedAt string `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at" form:"created_at"` //创建时间
	UpdatedAt string `gorm:"column:updated_at;type:datetime;comment:更新时间" json:"updated_at" form:"updated_at"` //更新时间
}

配置项信息存储表

func Getconfigure

func Getconfigure(name string) Configure

获取配置项的详情值

name	要获取的配置项的配置下标

func List added in v0.1.36

func List(group string) ([]Configure, error)

获取配置项列表信息

group	分组下标KEY

func (*Configure) TableName added in v0.0.6

func (c *Configure) TableName() string

表名

type ConfigureGroup added in v0.1.11

type ConfigureGroup struct {
	Id          uint   `gorm:"column:id;primaryKey;NOT NULL" json:"id" form:"id"`                                          // 自增ID
	Fid         uint   `gorm:"column:fid;default:0;NOT NULL;comment:'上级分组ID'" json:"fid" form:"fid"`                       // 上级分组ID
	NameGroup   string `gorm:"column:name_group;NOT NULL;comment:'分组名_key值'" json:"name_group" form:"name_group"`          // 分组KEY下标
	NameGroupCn string `gorm:"column:name_group_cn;NOT NULL;comment:'分组值-中文名称'" json:"name_group_cn" form:"name_group_cn"` // 分组名称
}

配置项分组信息

func GroupList added in v0.1.11

func GroupList(fid uint) ([]ConfigureGroup, error)

获取配置项分组列表[因配置项分组不会经常获取,所以此处不进行分组缓存,仅进行基础的配置项缓存]

fid	父级分类ID[0xffff表示获取全部]

func (*ConfigureGroup) TableName added in v0.1.11

func (c *ConfigureGroup) TableName() string

type ConfigureUser

type ConfigureUser struct {
	UserId    uint   `gorm:"column:user_id;primaryKey;comment:用户ID" json:"user_id" form:"user_id"`               //用户ID
	Configure string `gorm:"column:configure;type:longtext;comment:配置信息JSON串" json:"configure" form:"configure"` //配置信息JSON串
}

用户个性化配置项存储表

func (*ConfigureUser) TableName added in v0.0.6

func (c *ConfigureUser) TableName() string

type ConfigureUsers added in v0.2.67

type ConfigureUsers struct {
	Id          uint64  `gorm:"column:id;type:bigint unsigned;not null;autoIncrement;primaryKey" json:"-" form:"-"`
	Uid         uint    `gorm:"column:uid;type:int unsigned;default:0;comment:用户ID" json:"-" form:"-"`                                    // 用户ID
	Fid         uint64  `gorm:"column:fid;type:bigint unsigned;default:0;comment:上级配置项" json:"-" form:"-"`                                // 上级配置项ID
	Fids        string  `gorm:"column:fids;type:text;comment:上级ID列表,拼接" json:"-" form:"-"`                                                // 上级配置项ID列表,拼接
	Name        string  `gorm:"column:name;type:varchar(100);index;comment:配置项key" json:"name" form:"name"`                               //配置项key
	Types       string  `gorm:"column:types;type:varchar(20);index;comment:配置项类型" json:"types" form:"types"`                              //配置项类型
	ValueBool   uint8   `gorm:"column:value_bool;type:tinyint unsigned;default:0;comment:bool类型的值存储" json:"value_bool" form:"value_bool"` // bool类型的值存储 uint8
	ValueString string  `gorm:"column:value_string;type:text;comment:字符串类型配置" json:"value_string" form:"value_string"`                    // 字符串类型配置
	ValueInt    int64   `gorm:"column:value_int;type:bigint;default:0;comment:int类型配置" json:"value_int,string" form:"value_int"`          // int类型配置
	ValueFloat  float64 `gorm:"column:value_float;type:double;default:0;comment:float类型配置" json:"value_float" form:"value_float"`         // float类型配置
	CreatedAt   string  `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at" form:"created_at"`                         //创建时间
	UpdatedAt   string  `gorm:"column:updated_at;type:datetime;comment:更新时间" json:"updated_at" form:"updated_at"`                         //更新时间
}

配置项信息存储表

func Get added in v0.2.67

func Get(uid uint, name string) (*ConfigureUsers, error)

获取配置项信息

uid		用户ID
name	配置项路径及名称

func Gets added in v0.2.67

func Gets(uid uint, name []string) ([]ConfigureUsers, error)

获取配置项组列表

uid		用户ID
names	配置项路径及名称

func (*ConfigureUsers) TableName added in v0.2.67

func (c *ConfigureUsers) TableName() string

表名

Jump to

Keyboard shortcuts

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