Documentation ¶
Index ¶
- Constants
- Variables
- func Cast(value any, typ CastType) (any, error)
- func CastSlice[T any](slice []T, typ CastType) ([]any, error)
- func CastToArray(value any) ([]any, error)
- func CastToBool(value any) (*bool, error)
- func CastToDecimal(value any) (*float64, error)
- func CastToInteger(value any) (*int64, error)
- func CastToObject(value any) (map[string]any, error)
- func CastToString(value any) (*string, error)
- func CheckRuntimeVersion(minVersion Version, maxVersion Version) (err error)
- func ClearDir(dir string) (err error)
- func ConvertChildModels[R any, M Model[R]](helper *ModelHelper, field string, models []M) ([]R, error)
- func CopyFile(sourceFile string, targetFile string) (err error)
- func DescN(title string, kvs ...DescKeyValue) string
- func ErrN(title string, kvs ...DescKeyValue) error
- func ErrW(err error, title string, kvs ...DescKeyValue) error
- func EvalExpr(str string, data map[string]any, cast CastType) (any, error)
- func EvalFileTemplate(inputPath string, libraryPaths []string, outputPath string, ...) error
- func EvalStringTemplate(str string, data map[string]any, funcs template.FuncMap) (string, error)
- func FuncT[T any](expr bool, trueFunc func() T, falseFunc func() T) T
- func GetFileNames(globs []string, types []FileType) []string
- func GetRuntimeVersionCode() int32
- func GetSystemArch() string
- func GetSystemCurrentDir() (string, error)
- func GetSystemHomeDir() (string, error)
- func GetSystemHostname() (string, error)
- func GetSystemOs() string
- func GetSystemUsername() (string, error)
- func GetSystemVariables() map[string]string
- func Impossible()
- func IsConfigJsonFile(file string) bool
- func IsConfigTomlFile(file string) bool
- func IsConfigYamlFile(file string) bool
- func IsDirExists(dir string) bool
- func IsFileExists(file string) bool
- func IsJsonFile(file string) bool
- func IsTemplateFile(file string) bool
- func IsTemplateLibFile(file string) bool
- func IsTomlFile(file string) bool
- func IsYamlFile(file string) bool
- func LinkFile(sourceFile string, targetFile string) (err error)
- func LinkOrCopyFile(sourceFile string, targetFile string) (err error)
- func ListChildDirs(dir string) (names []string, err error)
- func MapAnyByStr[E any, M map[string]E](m M) map[string]any
- func MapCopy[K comparable, V any](source map[K]V) map[K]V
- func MapKeys[K comparable, V any](m map[K]V) []K
- func MapMerge(target map[string]any, source map[string]any, merge map[string]MapMergeMode, ...) (map[string]any, map[string]any, error)
- func MapValues[K comparable, V any](m map[K]V) []V
- func ParseFloat32(str string) (float32, error)
- func ParseFloat64(str string) (float64, error)
- func ParseInt32(str string) (int, error)
- func ParseInt64(str string) (int64, error)
- func RandomString(len int) (string, error)
- func ReadJsonFile(file string, model any) error
- func ReadTomlFile(file string, model any) error
- func ReadYamlFile(file string, model any) error
- func RegexMatch(regex *regexp.Regexp, str string) (matched bool, values map[string]string)
- func RemakeDir(dir string) (err error)
- func RemoveFileExt(file string) string
- func Ternary[T any](expr bool, trueValue T, falseValue T) T
- func TernaryFunc[T any](expr bool, trueFunc func() T, falseFunc func() T) T
- func ValT[T any](expr bool, trueValue T, falseValue T) T
- type CastType
- type Desc
- type DescBody
- type DescExtraKeyValuesFunc
- type DescKeyValue
- type DescKeyValues
- type DescKeyValuesFunc
- type DescList
- type Error
- type EvalData
- type EvalDataset
- type EvalFuncs
- type Evaluator
- func (e *Evaluator) ClearRoot() *Evaluator
- func (e *Evaluator) DescExtraKeyValues() KVS
- func (e *Evaluator) EvalBoolExpr(expr string) (bool, error)
- func (e *Evaluator) EvalExpr(expr string, cast CastType) (any, error)
- func (e *Evaluator) EvalFileTemplate(inputPath string, libraryPaths []string, outputPath string) error
- func (e *Evaluator) EvalStringTemplate(str string) (string, error)
- func (e *Evaluator) GetData(name string) map[string]any
- func (e *Evaluator) GetMap(includeFuncs bool) map[string]any
- func (e *Evaluator) MergeData(name string, data map[string]any) *Evaluator
- func (e *Evaluator) MergeDataset(dataset EvalDataset) *Evaluator
- func (e *Evaluator) MergeFuncs(funcs EvalFuncs) *Evaluator
- func (e *Evaluator) SetData(name string, data map[string]any) *Evaluator
- func (e *Evaluator) SetDataset(dataset EvalDataset) *Evaluator
- func (e *Evaluator) SetFunc(name string, fn any) *Evaluator
- func (e *Evaluator) SetFuncs(funcs EvalFuncs) *Evaluator
- func (e *Evaluator) SetRoot(name string) *Evaluator
- func (e *Evaluator) SetRootData(name string, data map[string]any) *Evaluator
- type File
- type FileType
- type JsonSerializer
- func (s *JsonSerializer) GetFileExt() string
- func (s *JsonSerializer) GetFormat() SerializationFormat
- func (s *JsonSerializer) SerializeFile(file string, model any) error
- func (s *JsonSerializer) SetIndentSymbol(symbol string) *JsonSerializer
- func (s *JsonSerializer) SetPrefixSymbol(symbol string) *JsonSerializer
- type KVS
- type LogLevel
- type Logger
- func (l *Logger) Debug(format string, v ...any)
- func (l *Logger) DebugDesc(title string, kvs ...DescKeyValue)
- func (l *Logger) Error(format string, v ...any)
- func (l *Logger) ErrorDesc(title string, kvs ...DescKeyValue)
- func (l *Logger) Fatal(format string, v ...any)
- func (l *Logger) FatalDesc(title string, kvs ...DescKeyValue)
- func (l *Logger) GetDebugWriter() io.Writer
- func (l *Logger) GetErrorWriter() io.Writer
- func (l *Logger) GetFatalWriter() io.Writer
- func (l *Logger) GetInfoWriter() io.Writer
- func (l *Logger) GetPanicWriter() io.Writer
- func (l *Logger) GetWarnWriter() io.Writer
- func (l *Logger) Info(format string, v ...any)
- func (l *Logger) InfoDesc(title string, kvs ...DescKeyValue)
- func (l *Logger) IsDebugEnabled() bool
- func (l *Logger) IsErrorEnabled() bool
- func (l *Logger) IsInfoEnabled() bool
- func (l *Logger) IsWarnEnabled() bool
- func (l *Logger) Panic(format string, v ...any)
- func (l *Logger) PanicDesc(title string, kvs ...DescKeyValue)
- func (l *Logger) Warn(format string, v ...any)
- func (l *Logger) WarnDesc(title string, kvs ...DescKeyValue)
- type MapMergeMode
- type Model
- type ModelHelper
- func (h *ModelHelper) AddVariable(key string, value any) *ModelHelper
- func (h *ModelHelper) CheckStringItemEmpty(field string, items []string) error
- func (h *ModelHelper) Child(field string) *ModelHelper
- func (h *ModelHelper) ChildItem(field string, index int) *ModelHelper
- func (h *ModelHelper) GetStringVariable(key string) string
- func (h *ModelHelper) Item(index int) *ModelHelper
- func (h *ModelHelper) NewError(reason string, extra ...DescKeyValue) error
- func (h *ModelHelper) NewValueEmptyError() error
- func (h *ModelHelper) NewValueInvalidError(value any) error
- func (h *ModelHelper) Warn(reason string, extra ...DescKeyValue)
- func (h *ModelHelper) WarnValueUnsound(value any)
- func (h *ModelHelper) WarnValueUseless(value any)
- func (h *ModelHelper) WrapError(err error, reason string, extra ...DescKeyValue) error
- func (h *ModelHelper) WrapValueInvalidError(err error, value any) error
- type SerializationFormat
- type SerializationMetadata
- type Serializer
- type System
- type TomlSerializer
- func (s *TomlSerializer) GetFileExt() string
- func (s *TomlSerializer) GetFormat() SerializationFormat
- func (s *TomlSerializer) SerializeFile(file string, model any) error
- func (s *TomlSerializer) SetArraysMultiline(multiline bool) *TomlSerializer
- func (s *TomlSerializer) SetIndentSymbol(symbol string) *TomlSerializer
- func (s *TomlSerializer) SetIndentTables(indent bool) *TomlSerializer
- func (s *TomlSerializer) SetTablesInline(inline bool) *TomlSerializer
- type Value
- type Version
- type YamlSerializer
Constants ¶
View Source
const ( MapMergeModeReplace MapMergeMode = "replace" MapMergeModeInsert MapMergeMode = "insert" MapMergeModeRootKey string = "$root" )
Variables ¶
View Source
var JsonSerializerDefault = NewJsonSerializer("", " ")
View Source
var TomlSerializerDefault = NewTomlSerializer(false, true, true, " ")
View Source
var YamlSerializerDefault = NewYamlSerializer(2)
Functions ¶
func CastToArray ¶
func CastToBool ¶
func CastToDecimal ¶
func CastToInteger ¶
func CastToString ¶
func CheckRuntimeVersion ¶
func ConvertChildModels ¶
func ConvertChildModels[R any, M Model[R]](helper *ModelHelper, field string, models []M) ([]R, error)
func DescN ¶
func DescN(title string, kvs ...DescKeyValue) string
func ErrN ¶
func ErrN(title string, kvs ...DescKeyValue) error
func EvalFileTemplate ¶
func EvalStringTemplate ¶
func GetFileNames ¶
func GetRuntimeVersionCode ¶
func GetRuntimeVersionCode() int32
func GetSystemArch ¶
func GetSystemArch() string
func GetSystemCurrentDir ¶
func GetSystemHomeDir ¶
func GetSystemHostname ¶
func GetSystemOs ¶
func GetSystemOs() string
func GetSystemUsername ¶
func GetSystemVariables ¶
func Impossible ¶
func Impossible()
func IsConfigJsonFile ¶
func IsConfigTomlFile ¶
func IsConfigYamlFile ¶
func IsDirExists ¶
func IsFileExists ¶
func IsJsonFile ¶
func IsTemplateFile ¶
func IsTemplateLibFile ¶
func IsTomlFile ¶
func IsYamlFile ¶
func LinkOrCopyFile ¶
func ListChildDirs ¶
func MapCopy ¶
func MapCopy[K comparable, V any](source map[K]V) map[K]V
func MapKeys ¶
func MapKeys[K comparable, V any](m map[K]V) []K
func MapValues ¶
func MapValues[K comparable, V any](m map[K]V) []V
func ParseFloat32 ¶
func ParseFloat64 ¶
func ParseInt32 ¶
func ParseInt64 ¶
func RandomString ¶
func ReadJsonFile ¶
func ReadTomlFile ¶
func ReadYamlFile ¶
func RegexMatch ¶
func RemoveFileExt ¶
func TernaryFunc ¶
Types ¶
type DescBody ¶
type DescBody []string
func NewDescBody ¶
func NewDescBody(kvs DescKeyValues) DescBody
type DescExtraKeyValuesFunc ¶
type DescExtraKeyValuesFunc interface {
DescExtraKeyValues() DescKeyValues
}
type DescKeyValue ¶
func KV ¶
func KV(key string, value any) DescKeyValue
func NewDescKeyValue ¶
func NewDescKeyValue(key string, value any) DescKeyValue
func Reason ¶
func Reason(reason any) DescKeyValue
func (DescKeyValue) DescKeyValues ¶
func (kv DescKeyValue) DescKeyValues() DescKeyValues
func (DescKeyValue) String ¶
func (kv DescKeyValue) String() string
type DescKeyValues ¶
type DescKeyValues []DescKeyValue
func (DescKeyValues) DescKeyValues ¶
func (kvs DescKeyValues) DescKeyValues() DescKeyValues
type DescKeyValuesFunc ¶
type DescKeyValuesFunc interface {
DescKeyValues() DescKeyValues
}
type Error ¶
type Error struct { Details DescList Stacks errors.StackTrace // contains filtered or unexported fields }
type EvalDataset ¶
func (EvalDataset) MergeData ¶
func (ds EvalDataset) MergeData(name string, data map[string]any) EvalDataset
func (EvalDataset) MergeDataset ¶
func (ds EvalDataset) MergeDataset(dataset EvalDataset) EvalDataset
func (EvalDataset) SetData ¶
func (ds EvalDataset) SetData(name string, data map[string]any) EvalDataset
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
func NewEvaluator ¶
func NewEvaluator() *Evaluator
func (*Evaluator) DescExtraKeyValues ¶
func (*Evaluator) EvalFileTemplate ¶
func (*Evaluator) EvalStringTemplate ¶
func (*Evaluator) MergeDataset ¶
func (e *Evaluator) MergeDataset(dataset EvalDataset) *Evaluator
func (*Evaluator) MergeFuncs ¶
func (*Evaluator) SetDataset ¶
func (e *Evaluator) SetDataset(dataset EvalDataset) *Evaluator
type FileType ¶
type FileType string
const ( FileTypeConfigYaml FileType = "config-yaml" FileTypeConfigToml FileType = "config-toml" FileTypeConfigJson FileType = "config-json" FileTypeTemplate FileType = "template" FileTypeTemplateLib FileType = "template-lib" FileTypeYaml FileType = "yaml" FileTypeToml FileType = "toml" FileTypeJson FileType = "json" FileTypePlain FileType = "plain" )
func GetFileType ¶
type JsonSerializer ¶
func NewJsonSerializer ¶
func NewJsonSerializer(prefixSymbol, indentSymbol string) *JsonSerializer
func (*JsonSerializer) GetFileExt ¶
func (s *JsonSerializer) GetFileExt() string
func (*JsonSerializer) GetFormat ¶
func (s *JsonSerializer) GetFormat() SerializationFormat
func (*JsonSerializer) SerializeFile ¶
func (s *JsonSerializer) SerializeFile(file string, model any) error
func (*JsonSerializer) SetIndentSymbol ¶
func (s *JsonSerializer) SetIndentSymbol(symbol string) *JsonSerializer
func (*JsonSerializer) SetPrefixSymbol ¶
func (s *JsonSerializer) SetPrefixSymbol(symbol string) *JsonSerializer
type KVS ¶
type KVS = DescKeyValues
type Logger ¶
type Logger struct { Level LogLevel // contains filtered or unexported fields }
func (*Logger) DebugDesc ¶
func (l *Logger) DebugDesc(title string, kvs ...DescKeyValue)
func (*Logger) ErrorDesc ¶
func (l *Logger) ErrorDesc(title string, kvs ...DescKeyValue)
func (*Logger) FatalDesc ¶
func (l *Logger) FatalDesc(title string, kvs ...DescKeyValue)
func (*Logger) GetDebugWriter ¶
func (*Logger) GetErrorWriter ¶
func (*Logger) GetFatalWriter ¶
func (*Logger) GetInfoWriter ¶
func (*Logger) GetPanicWriter ¶
func (*Logger) GetWarnWriter ¶
func (*Logger) InfoDesc ¶
func (l *Logger) InfoDesc(title string, kvs ...DescKeyValue)
func (*Logger) IsDebugEnabled ¶
func (*Logger) IsErrorEnabled ¶
func (*Logger) IsInfoEnabled ¶
func (*Logger) IsWarnEnabled ¶
func (*Logger) PanicDesc ¶
func (l *Logger) PanicDesc(title string, kvs ...DescKeyValue)
func (*Logger) WarnDesc ¶
func (l *Logger) WarnDesc(title string, kvs ...DescKeyValue)
type MapMergeMode ¶
type MapMergeMode string
type Model ¶
type Model[R any] interface { Convert(helper *ModelHelper) (R, error) }
type ModelHelper ¶
type ModelHelper struct { Logger *Logger Title string Source string Field string Variables map[string]any }
func NewModelHelper ¶
func NewModelHelper(logger *Logger, title, source string) *ModelHelper
func (*ModelHelper) AddVariable ¶
func (h *ModelHelper) AddVariable(key string, value any) *ModelHelper
func (*ModelHelper) CheckStringItemEmpty ¶
func (h *ModelHelper) CheckStringItemEmpty(field string, items []string) error
func (*ModelHelper) Child ¶
func (h *ModelHelper) Child(field string) *ModelHelper
func (*ModelHelper) ChildItem ¶
func (h *ModelHelper) ChildItem(field string, index int) *ModelHelper
func (*ModelHelper) GetStringVariable ¶
func (h *ModelHelper) GetStringVariable(key string) string
func (*ModelHelper) Item ¶
func (h *ModelHelper) Item(index int) *ModelHelper
func (*ModelHelper) NewError ¶
func (h *ModelHelper) NewError(reason string, extra ...DescKeyValue) error
func (*ModelHelper) NewValueEmptyError ¶
func (h *ModelHelper) NewValueEmptyError() error
func (*ModelHelper) NewValueInvalidError ¶
func (h *ModelHelper) NewValueInvalidError(value any) error
func (*ModelHelper) Warn ¶
func (h *ModelHelper) Warn(reason string, extra ...DescKeyValue)
func (*ModelHelper) WarnValueUnsound ¶
func (h *ModelHelper) WarnValueUnsound(value any)
func (*ModelHelper) WarnValueUseless ¶
func (h *ModelHelper) WarnValueUseless(value any)
func (*ModelHelper) WrapError ¶
func (h *ModelHelper) WrapError(err error, reason string, extra ...DescKeyValue) error
func (*ModelHelper) WrapValueInvalidError ¶
func (h *ModelHelper) WrapValueInvalidError(err error, value any) error
type SerializationFormat ¶
type SerializationFormat string
const ( SerializationFormatYaml SerializationFormat = "yaml" SerializationFormatToml SerializationFormat = "toml" SerializationFormatJson SerializationFormat = "json" )
func GetSerializationFormat ¶
func GetSerializationFormat(fileType FileType) SerializationFormat
type SerializationMetadata ¶
type SerializationMetadata struct { File string Format SerializationFormat }
func DeserializeDir ¶
func DeserializeFile ¶
func DeserializeFile(file string, format SerializationFormat, model any) (metadata *SerializationMetadata, err error)
type Serializer ¶
type Serializer interface { GetFormat() SerializationFormat GetFileExt() string SerializeFile(file string, model any) error }
type System ¶
type TomlSerializer ¶
type TomlSerializer struct { TablesInline bool IndentTables bool ArraysMultiline bool IndentSymbol string }
func NewTomlSerializer ¶
func NewTomlSerializer(tableInline, indentTables, arraysMultiline bool, indentSymbol string) *TomlSerializer
func (*TomlSerializer) GetFileExt ¶
func (s *TomlSerializer) GetFileExt() string
func (*TomlSerializer) GetFormat ¶
func (s *TomlSerializer) GetFormat() SerializationFormat
func (*TomlSerializer) SerializeFile ¶
func (s *TomlSerializer) SerializeFile(file string, model any) error
func (*TomlSerializer) SetArraysMultiline ¶
func (s *TomlSerializer) SetArraysMultiline(multiline bool) *TomlSerializer
func (*TomlSerializer) SetIndentSymbol ¶
func (s *TomlSerializer) SetIndentSymbol(symbol string) *TomlSerializer
func (*TomlSerializer) SetIndentTables ¶
func (s *TomlSerializer) SetIndentTables(indent bool) *TomlSerializer
func (*TomlSerializer) SetTablesInline ¶
func (s *TomlSerializer) SetTablesInline(inline bool) *TomlSerializer
type Version ¶
type Version string
func GetRuntimeVersion ¶
func GetRuntimeVersion() Version
func (Version) GetVersionCode ¶
type YamlSerializer ¶
type YamlSerializer struct {
Indent int
}
func NewYamlSerializer ¶
func NewYamlSerializer(indent int) *YamlSerializer
func (*YamlSerializer) GetFileExt ¶
func (s *YamlSerializer) GetFileExt() string
func (*YamlSerializer) GetFormat ¶
func (s *YamlSerializer) GetFormat() SerializationFormat
func (*YamlSerializer) SerializeFile ¶
func (s *YamlSerializer) SerializeFile(file string, model any) error
func (*YamlSerializer) SetIndent ¶
func (s *YamlSerializer) SetIndent(indent int) *YamlSerializer
Click to show internal directories.
Click to hide internal directories.