xgodbconfig

package
v0.3.15 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: BSD-3-Clause-Clear Imports: 6 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 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 SetInteface added in v0.3.14

func SetInteface(inf Interfaces)

设置外部数据源

inf	外部数据源信息

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 SetSystemConfigure added in v0.3.14

func SetSystemConfigure(conf Configure) error

设置配置项信息到数据库中

conf	待设置的配置项值

func SetText added in v0.0.3

func SetText(name, val string) error

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

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

Types

type Config

type Config struct {
	DB                  *gorm.DB
	ConfigTable         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
	// 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 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

表名

type Interfaces added in v0.3.14

type Interfaces interface {
	Getconfigure(name string) Configure                 // 获取配置项
	GroupList(fid uint) ([]ConfigureGroup, error)       // 分组列表
	GroupInserts(g []ConfigureGroup) error              // 分组插入
	List(group string) ([]Configure, error)             // 获取分组下配置项列表信息
	Setconfigure(conf Configure) error                  // 设置系统配置信息
	InsertsOrContinue(confs []Configure) error          // 初始化插入配置项
	Get(uid uint, name string) (*ConfigureUsers, error) // 获取用户配置项信息
	Set(c *ConfigureUsers) error                        // 用户配置项写入
}

如果使用外部数据源,需要实现的接口列表

Jump to

Keyboard shortcuts

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