setting

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package setting 设置项管理

Index

Constants

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

Variables

This section is empty.

Functions

This section is empty.

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" xml:"value"`
	Title string `json:"title" xml:"title"`
	Desc  string `json:"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) HandlePut added in v0.3.0

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

HandlePut 更新设置项

type GroupRequest

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

func (*GroupRequest) CTXSanitize

func (g *GroupRequest) CTXSanitize(v *web.Validation)

type GroupResponse

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

type ItemRequest

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

type ItemResponse

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

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

type Request

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

func (*Request) CTXSanitize

func (r *Request) CTXSanitize(v *web.Validation)

type Response

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

type Setting

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

Setting 设置项

func New

func New(s Store) *Setting

func (*Setting) Get added in v0.3.0

func (s *Setting) Get(id string) (*Group, bool)

Get 获取指定 ID 的 Group 实例

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) Register added in v0.3.0

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

Register 将对象 g 注册为配置项

要求 g 必须是一个具有可导出字段的结构体指针。

id 为注册对象的 ID,要求在 Setting 中具有唯一性; title 简要描述; desc 明细说明; attrs 对 g 中各个字段的说明,键名为字段名称;

type Store added in v0.3.0

type Store interface {
	// Update 将当前内容写入到存储对象
	Update(string, any) error

	// Insert 将内容第一次写入至存储对象
	Insert(string, any) error

	// Load 从存储对象加载数据至对象
	Load(string, any) error

	// Exists 是否存在提定 ID 的设置项
	Exists(string) (bool, error)
}

Store 设置项的存储接口

Directories

Path Synopsis
Package store 提供对 setting.Store 的实现
Package store 提供对 setting.Store 的实现

Jump to

Keyboard shortcuts

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