meta

package
v0.0.0-...-a78f517 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const EnvPrefix = "ATK_"

Variables

This section is empty.

Functions

func GetEnvPathMap

func GetEnvPathMap(model any, yamlTemplate string) map[string]string

GetEnvPathMap read the model and YAML config template (with comments and default values) to get the mapping of environment variable names to their corresponding config paths.

func GetEnvPathMapByModel

func GetEnvPathMapByModel(model any) map[string]string

GetEnvPathMapByModel use reflection to read struct fields and generate a mapping of environment variable names.

This is useful for generating environment variable names for all the config paths in the Config struct. The environment variable names are generated by converting the config path to uppercase and replacing all dots with underscores. For example, the config path `ip_region.db_path` will be converted to `ATK_IP_REGION_DB_PATH`.

The $$ is symbol for number.

Types

type OptionsMeta

type OptionsMeta struct {
	Title      string   `json:"title" yaml:"title"`
	Desc       string   `json:"desc" yaml:"desc"`
	Type       string   `json:"type" yaml:"type"`
	Options    []string `json:"options" yaml:"options"`
	Env        string   `json:"env" yaml:"env"`
	Path       string   `json:"path" yaml:"path"`
	PathText   string   `json:"path_title" yaml:"path_title"`
	Default    any      `json:"default" yaml:"default"`
	IsRoot     bool     `json:"is_root" yaml:"is_root"`
	HasChild   bool     `json:"has_child" yaml:"has_child"`
	AllowsSet  bool     `json:"allows_edit" yaml:"allows_edit"`
	CommentRaw string   `json:"comment_raw" yaml:"comment_raw"`
}

func GetOptionsMetaData

func GetOptionsMetaData(yamlTemplate string) ([]OptionsMeta, error)

GetOptionsMetaData returns the metadata of the config options from the YAML config template.

The YAML config template includes comments and default values. The format of the comments is as follows:

# Title (Desc) [Option1, Option2]

The metadata includes the title, description, type, options, environment variable name, path, and default value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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