vdef

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConverterFilters = map[string]mapconv.FilterFunc{
	"rfc3339":         strToTime,
	"path_to_reader":  pathToReader,
	"path_to_writer":  pathToWriter,
	"path_or_content": pathOrContent,
	"weekdays":        weekdaysFilter,
	"dereference":     dereferenceFilter,
	"base64encode":    base64Encode,
	"gib_to_mib": func(v interface{}) (interface{}, error) {
		if v == nil {
			return nil, nil
		}
		sv, ok := v.(int)
		if !ok {
			return nil, fmt.Errorf("invalid value: %v", v)
		}
		return size.GiBToMiB(sv), nil
	},
}

ConverterFilters mapconvでの変換時に利用されるフィルターの定義、definitionsに登録したものは実行時に動的に追加される

View Source
var FlagOptionsMap = map[string][]string{
	"os_type_simple": {
		"almalinux",
		"rockylinux",
		"miraclelinux",
		"ubuntu",
		"debian",
		"...",
	},
}

FlagOptionsMap CLIで指定するフラグでの静的な候補値一覧(cliタグで指定する)

Note: コード生成で利用されるため実行時に動的に変化する項目には利用できない

View Source
var TemplateFuncMap = template.FuncMap{

	"gib_to_mib": func(value interface{}) int {
		num := 0
		switch v := value.(type) {
		case int:
			num = v
		case int64:
			num = int(v)
		case json.Number:
			n, _ := v.Int64()
			num = int(n)
		}
		return size.GiBToMiB(num)
	},
	"mib_to_gib": func(value interface{}) int {
		num := 0
		switch v := value.(type) {
		case int:
			num = v
		case int64:
			num = int(v)
		case json.Number:
			n, _ := v.Int64()
			num = int(n)
		}
		return size.MiBToGiB(num)
	},
	"ignore_empty": func(value interface{}) interface{} {
		if util.IsEmpty(value) {
			return ""
		}
		return value
	},
	"ellipsis": ellipsis,
	"to_single_line": func(value interface{}) interface{} {
		v := fmt.Sprintf("%v", value)
		return strings.ReplaceAll(v, "\n", "\\n")
	},
	"first_line": func(value interface{}) interface{} {
		if value == nil {
			return nil
		}
		if v, ok := value.([]string); ok {
			if len(v) > 0 {
				return v[0]
			}
		}
		return ""
	},
	"weekdays": func(value interface{}) interface{} {
		if value == nil {
			return nil
		}
		weekdays, ok := value.([]types.EDayOfTheWeek)
		if !ok {
			return nil
		}
		if len(weekdays) == 7 {
			return "all"
		}

		var results []string
		for _, d := range weekdays {
			results = append(results, d.String())
		}
		return results
	},
	"switch_type": func(value interface{}) string {
		if value == nil {
			return "unknown"
		}
		v, ok := value.(*iaas.Switch)
		if !ok {
			return "unknown"
		}
		if len(v.Subnets) > 0 && v.Subnets[0].Internet != nil {
			return "switch+router"
		}
		return "switch"
	},
	"user_friendly_price": userFriendlyPriceString,
	"join": func(sep string, values []string) string {
		return strings.Join(values, sep)
	},
	"first_non_empty": func(values ...interface{}) interface{} {
		for _, v := range values {
			if !util.IsEmpty(v) {
				return v
			}
		}
		return nil
	},
	"unix_time_to_date": func(value int64) *time.Time {
		if value <= 0 {
			return nil
		}
		v := time.Unix(value/1000, 0)
		return &v
	},
	"file": func(path string) string {
		if path == "" {
			return ""
		}

		poc, err := homedir.Expand(path)
		if err != nil {
			return ""
		}

		data, err := os.ReadFile(poc)
		if err != nil {
			return ""
		}
		return string(data)
	},
	"trim_space": strings.TrimSpace,
}

Functions

func Keys

func Keys(key string) ([]string, bool)

func ValidatorAliases

func ValidatorAliases(zones []string) map[string]string

Types

This section is empty.

Jump to

Keyboard shortcuts

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