config

package
v0.0.0-...-ac7d4c8 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

配置文件的读取和写入 目前仅支持json格式配置文件

Index

Constants

View Source
const (
	CONFIG_MODE_GROUP       = "group"       //分组
	CONFIG_MODE_LIST        = "list"        //列表
	CONFIG_MODE_JUDGE       = "judge"       //判断
	CONFIG_MODE_SGINGLE     = "single"      //单选
	CONFIG_MODE_MULTI       = "multi"       //多选
	CONFIG_MODE_TEXTAREA    = "text"        //多行文本
	CONFIG_MODE_UPLOD_FILE  = "uploadFile"  //文件上传
	CONFIG_MODE_UPLOD_IMAGE = "uploadImage" //图片上传
)

配置类型

View Source
const (
	CONFIG_TYPE_STRING = "string" //字符串
	CONFIG_TYPE_INT    = "int"    //整形
	CONFIG_TYPE_UINT   = "uint"   //无符号整形
	CONFIG_TYPE_FLOAT  = "float"  //浮点数
	CONFIG_TYPE_BOOL   = "bool"   //布尔类型
	CONFIG_TYPE_SLICE  = "slice"  //数组类型=相当于Mode=category
	CONFIG_TYPE_OBJECT = "object" //对象类型
)

数据类型

Variables

This section is empty.

Functions

func Read

func Read(filename string, ptr interface{}, ptrs ...interface{}) error

配置读取,只读取json类型文件,可读到多个结构体上,如果配置不存在则创建一个

func RegMode

func RegMode(modeName string, fn func() string)

注册mode处理方法,返回新mode

func RegOptions

func RegOptions(optionGroup string, fn func() []*ValueOption)

注册配置的option,当获取配置的时候调用注册的方法,可用于动态创建options

func Write

func Write(filename string, ptr interface{}) error

配置写入,写入前先将json数据格式化,方便修改时易读

Types

type ConfigStruct

type ConfigStruct struct {
	Field   string          `json:"field"`   //字段名
	Name    string          `json:"name"`    //字段说明
	Desc    string          `json:"desc"`    //字段介绍
	Mode    string          `json:"mode"`    //字段模式 分类 判断 单选 多选 单行 多行
	Type    string          `json:"type"`    //数据类型 string int float bool array
	Options []*ValueOption  `json:"options"` //配置选项
	Childs  []*ConfigStruct `json:"childs"`  //子配置
}

配置结构体

func Dump

func Dump(conf interface{}) []*ConfigStruct

导出配置结构

type ValueOption

type ValueOption struct {
	Label string      `json:"label"`
	Value interface{} `json:"value"`
	Desc  string      `json:"desc"`
}

Jump to

Keyboard shortcuts

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