yaml

package module
v0.4.23 Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: ISC Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyYaml

func ApplyYaml(ex mains.Executable, yamlFile, yamlKey string, thunk UnmarshalThunk, om []OptionData)

ApplyYaml adds options read from a yaml file.

File: The filename searched comes from Executable.Program or the yamlFile argument. If yamlFile is set exactly this file is read. If yamlFile is not set, A search is executed in the directories ~/apps .. and /etc. The filename searched is [program]-[hostname].yaml and [program].yaml.

Content: If the file does not eixst, no action is taken. If the file is empty, no action is taken.

The top entry in the yaml file is expected to be a dictionary of dictionaries. The key searched for in the top level dictionary is the yamlKey argument or “options” if not set.

thunk needs to in otuside of the library for typoing reasons and is implemented similar to the below. y is the variable receiving parsed yaml data. The om list is then svcaned for its Y pointers to copy yaml settings to options.

func applyYaml(bytes []byte, unmarshal mains.UnmarshalFunc, yamlDictionaryKey string) (hasData bool, err error) {
  yamlContentObject := map[string]*YamlData{} // need map[string] because yaml top level is dictionary
  if err = unmarshal(bytes, &yamlContentObject); err != nil {
    return
  }
  yamlDataPointer := yamlContentObject[yamlDictionaryKey] // pick out the options dictionary value
  if hasData = yamlDataPointer != nil; !hasData {
    return
  }
  y = *yamlDataPointer
  return
}

func FindFile

func FindFile(filename0, program string) (out string, bytes []byte)

FindFile locates and read the yaml file

func GetTopLevelKey

func GetTopLevelKey(topKey string) (key string)

GetTopLevelKey gets the top level key to use

Types

type UnmarshalFunc

type UnmarshalFunc func(in []byte, out interface{}) (err error) // yaml.Unmarshal

type UnmarshalThunk

type UnmarshalThunk func(bytes []byte, unmarshal UnmarshalFunc, yamlKey string) (hasDate bool, err error)

Jump to

Keyboard shortcuts

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