configstruct

package
v1.54.4 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package configstruct parses unstructured maps into structures

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Set

func Set(config configmap.Getter, opt interface{}) (err error)

Set interprets the field names in defaults and looks up config values in the config passed in. Any values found in config will be set in the opt structure.

opt must be a pointer to a struct. The struct should have entirely public fields. The field names are converted from CamelCase to snake_case and looked up in the config supplied or a `config:"field_name"` is looked up.

If items are found then they are converted from string to native types and set in opt.

All the field types in the struct must implement fmt.Scanner.

func StringToInterface

func StringToInterface(def interface{}, in string) (newValue interface{}, err error)

StringToInterface turns in into an interface{} the same type as def

Types

type Item

type Item struct {
	Name  string // snake_case
	Field string // CamelCase
	Num   int    // number of the field in the struct
	Value interface{}
}

Item describes a single entry in the options structure

func Items

func Items(opt interface{}) (items []Item, err error)

Items parses the opt struct and returns a slice of Item objects.

opt must be a pointer to a struct. The struct should have entirely public fields.

The config_name is looked up in a struct tag called "config" or if not found is the field name converted from CamelCase to snake_case.

Jump to

Keyboard shortcuts

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