setting

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package setting 设置项管理

Index

Constants

View Source
const (
	TypeBool   = "bool"
	TypeNumber = "number"
	TypeString = "string"
)

Variables

This section is empty.

Functions

func Install

func Install(parent *web.Module, db *orm.DB) error

Types

type Attribute

type Attribute struct {
	ID          string
	Title, Desc web.LocaleStringer
	Multiple    bool // 多行文本
	Candidate   []Candidate
}

Attribute 对配置对象各个字段的描述

type Candidate

type Candidate struct {
	Value       any
	Title, Desc web.LocaleStringer // 值的字面文本以及详细说明,desc 可以为空。
}

Candidate 修改数据

type CandidateResponse

type CandidateResponse struct {
	Value any    `json:"value" yaml:"value" xml:"value"`
	Title string `json:"title" yaml:"title" xml:"title"`
	Desc  string `json:"desc,omitempty" yaml:"desc,omitempty" xml:"desc,omitempty"`
}

type Group

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

Group 对配置对象的操作接口

func (*Group) HandleGet

func (g *Group) HandleGet(ctx *web.Context) web.Responser

HandleGet 获取设置项

func (*Group) HandlePatch

func (g *Group) HandlePatch(ctx *web.Context) web.Responser

HandlePatch 更新设置项

func (*Group) Load

func (g *Group) Load() error

Load 加载数据库的数据至关联的对象

func (*Group) Update

func (g *Group) Update() error

type GroupRequest

type GroupRequest struct {
	XMLName struct{}       `json:"-" yaml:"-" xml:"group"`
	ID      string         `json:"id,omitempty" yaml:"id,omitempty" xml:"id,attr,omitempty"`
	Items   []*ItemRequest `json:"items" yaml:"items" xml:"item"`
	// contains filtered or unexported fields
}

func (*GroupRequest) CTXSanitize

func (g *GroupRequest) CTXSanitize(ctx *web.Context, v *web.Validation)

type GroupResponse

type GroupResponse struct {
	XMLName struct{}        `json:"-" yaml:"-" xml:"group"`
	ID      string          `json:"id" yaml:"id" xml:"id,attr"`
	Title   string          `json:"title" yaml:"title" xml:"title"`
	Desc    string          `json:"desc" yaml:"desc" xml:"desc"`
	Items   []*ItemResponse `json:"items,omitempty" yaml:"items,omitempty" xml:"item,omitempty"`
}

type ItemRequest

type ItemRequest struct {
	ID       string   `json:"id" yaml:"id" xml:"id,attr"`
	Value    any      `json:"value" yaml:"value" xml:"-"`
	XMLValue []string `json:"-" yaml:"-" xml:"value"` // XML 无法解析到 any 类型
}

type ItemResponse

type ItemResponse struct {
	ID       string `json:"id" yaml:"id" xml:"id,attr"`
	Title    string `json:"title" yaml:"title" xml:"title"`
	Desc     string `json:"desc" yaml:"desc" xml:"desc"`
	Value    any    `json:"value" yaml:"value" xml:"value"`
	Type     string `json:"type,omitempty" yaml:"type,omitempty" xml:"type,attr,omitempty"`
	Multiple bool   `json:"multiple,omitempty" yaml:"multiple,omitempty" xml:"multiple,attr,omitempty"`
	Slice    bool   `json:"slice,omitempty" yaml:"slice,omitempty" xml:"slice,attr,omitempty"`

	Candidate []*CandidateResponse `json:"candidate,omitempty" yaml:"candidate,omitempty" xml:"candidate,omitempty"`
}

type Request

type Request struct {
	XMLName struct{}        `json:"-" yaml:"-" xml:"setting"`
	Groups  []*GroupRequest `json:"groups,omitempty" yaml:"groups,omitempty" xml:"group,omitempty"`
	// contains filtered or unexported fields
}

func (*Request) CTXSanitize

func (r *Request) CTXSanitize(ctx *web.Context, v *web.Validation)

type Response

type Response struct {
	XMLName struct{}         `json:"-" yaml:"-" xml:"setting"`
	Groups  []*GroupResponse `json:"groups,omitempty" yaml:"groups,omitempty" xml:"groups,omitempty"`
}

type Setting

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

Setting 设置项

所有的设置以结构体为单位保存在数据库, 每个结构体可以有多个基本字段。

func New

func New(parent *web.Module, db *orm.DB) *Setting

func (*Setting) HandleGet

func (s *Setting) HandleGet(ctx *web.Context) web.Responser

HandleGet 获取当前用户的所有设置项

func (*Setting) HandlePatch

func (s *Setting) HandlePatch(ctx *web.Context) web.Responser

func (*Setting) NewGroup

func (s *Setting) NewGroup(id string, g any, title, desc web.LocaleStringer, attrs map[string]*Attribute, notify func()) (*Group, error)

Register 注册配置对象

id 表示该设置对象的唯一 ID; title,desc 对该组设置项的描述; g 设置项的对象,要求该对象的所有字段都是基本类型; attrs 对 g 各个字段的描述,键名为字段名;

Jump to

Keyboard shortcuts

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