config

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 21 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// ParseError occurs when an error occurs in the configuration parsing
	ParseError = ErrorType(iota)

	// CheckError occurs when an error occurs in the configuration checking
	CheckError

	// ReloadParseError occurs when an error occurs in the configuration
	// reloaded and parsing
	ReloadParseError

	// ReloadCheckError occurs when an error occurs in the configuration
	// reloaded and checking
	ReloadCheckError
)
View Source
const MaxConfigFileSize = 32 * 1024 * 1024

Variables

View Source
var (
	TypeUnknown = Type{Id: id.Uint64Id(&typeIdCxt), Name: "unknown"}
	TypeYaml    = Type{Id: id.Uint64Id(&typeIdCxt), Name: "yaml", Suffixes: []string{"yaml", "yml"}, Unmarshaler: yaml.Unmarshal}
	TypeJson    = Type{Id: id.Uint64Id(&typeIdCxt), Name: "json", Suffixes: []string{"json"}, Unmarshaler: json.Unmarshal}
)
View Source
var ConfigSizeTooLargeError = fmt.Errorf("配置文件大小过大,超过限定大小(%s)", unit.Size(MaxConfigFileSize))

Functions

func Handle

func Handle(c any) error

func HandleDefault

func HandleDefault(c any) error

func HandleWith

func HandleWith[C any](c C) (C, error)

func LoggerErrorCallback

func LoggerErrorCallback(logger *log.Logger) func(err *Error)

func MustHandleWith

func MustHandleWith[C any](c C) C

func PostHandle

func PostHandle(c any) error

func PreHandle

func PreHandle(c any) error

Types

type ConfigReloadChecker

type ConfigReloadChecker[C any] func(oc, nc *C) error

type Context

type Context[C any] struct {
	Parser
	// contains filtered or unexported fields
}

func NewContext

func NewContext[C any](newConfig func() *C, options ...Option[C]) *Context[C]

func (*Context[C]) Config

func (c *Context[C]) Config() *C

func (*Context[C]) InitConfig

func (c *Context[C]) InitConfig() error

func (*Context[C]) RegisterConfigReloadChecker

func (c *Context[C]) RegisterConfigReloadChecker(checker ConfigReloadChecker[C]) uint64

func (*Context[C]) RegisterConfigReloadedCallback

func (c *Context[C]) RegisterConfigReloadedCallback(callback OnConfigReloaded[C]) uint64

func (*Context[C]) ReloadConfig

func (c *Context[C]) ReloadConfig() error

func (*Context[C]) UnregisterConfigReloadChecker

func (c *Context[C]) UnregisterConfigReloadChecker(id uint64)

func (*Context[C]) UnregisterConfigReloadedCallback

func (c *Context[C]) UnregisterConfigReloadedCallback(id uint64)

type Error

type Error struct {
	Type ErrorType
	Err  error
}

func (Error) Error

func (e Error) Error() string

type ErrorType

type ErrorType int

func (ErrorType) Type

func (t ErrorType) Type() string

Type method return the name of error type, If the error type is undefined, return UNKNOWN_ERROR

type OnConfigReloaded

type OnConfigReloaded[C any] func(oc, nc *C)

type Option

type Option[C any] option.CustomOption[*Context[C]]

func AddBytes

func AddBytes[C any](bs []byte, typ Type) Option[C]

func AddFile

func AddFile[C any](path string, typ *Type) Option[C]

func AddFilePrefix

func AddFilePrefix[C any](prefix string, types ...Type) Option[C]

func ErrorCallback

func ErrorCallback[C any](callback func(err *Error)) Option[C]

func SetBytes

func SetBytes[C any](bs []byte, typ Type) Option[C]

func SetFile

func SetFile[C any](path string, typ *Type) Option[C]

func SetFilePrefix

func SetFilePrefix[C any](prefix string, types ...Type) Option[C]

type Parser

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

func (*Parser) AddBytes

func (p *Parser) AddBytes(bs []byte, typ Type)

func (*Parser) AddFile

func (p *Parser) AddFile(path string, typ *Type)

func (*Parser) AddFilePrefix

func (p *Parser) AddFilePrefix(prefix string, types ...Type)

func (*Parser) SetBytes

func (p *Parser) SetBytes(bs []byte, typ Type)

func (*Parser) SetFile

func (p *Parser) SetFile(path string, typ *Type)

func (*Parser) SetFilePrefix

func (p *Parser) SetFilePrefix(prefix string, types ...Type)

func (*Parser) Unmarshal

func (p *Parser) Unmarshal(c interface{}) error

type PostHandleAfterChildrenConfig

type PostHandleAfterChildrenConfig interface {
	PostHandleAfterChildren() error
}

type PostHandlerConfig

type PostHandlerConfig interface {
	PostHandle() error
}

type PostModifyAfterChildrenConfig

type PostModifyAfterChildrenConfig interface {
	PostModifyAfterChildren() (nc any, modified bool, err error)
}

type PostModifyConfig

type PostModifyConfig interface {
	PostModify() (nc any, modified bool, err error)
}

type PreHandleAfterChildrenConfig

type PreHandleAfterChildrenConfig interface {
	PreHandleAfterChildren()
}

type PreHandlerConfig

type PreHandlerConfig interface {
	PreHandle()
}

type PreModifyAfterChildrenConfig

type PreModifyAfterChildrenConfig interface {
	PreModifyAfterChildren() (nc any, modified bool)
}

type PreModifyConfig

type PreModifyConfig interface {
	PreModify() (nc any, modified bool)
}

type Type

type Type struct {
	Id          uint64
	Name        string
	Suffixes    []string
	Unmarshaler func([]byte, interface{}) error
}

func NewType

func NewType(Name string, Suffixes []string, Unmarshaler func([]byte, interface{}) error) Type

func ProbeType

func ProbeType(path string) Type

Jump to

Keyboard shortcuts

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