marshaler

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TAG_FLAG       = "flag"
	TAG_HELPTEXT   = "helptext"
	TAG_BINDING    = "binding"
	TAG_DEFAULT    = "default"
	TAG_VALIDATORS = "validators"

	TAG_BINDING_REQUIRED = "required"
	TAG_BINDING_IS_BOOL  = "bool"
)

Tags are the way the data can be marshalled into a given struct.

Variables

This section is empty.

Functions

func MarshallCommandArguments

func MarshallCommandArguments(args string, v interface{}) error

Marshall a given string slice into the given struct. This method will iterate over the given slice and check every `flag` tags in order to fill it with the correct value.

Example:

type myArgs struct {
    Directory  string `flag:"-d" helptext:"directory" binding:"false" default:"./" validators:"path"`
	   ShowHidden bool   `flag:"-h" helptext:"shows hidden folders" binding:"isBool"`
}

argsList := ["-d", "/memes", "-h"] args := &myArgs{}

MarshallCommandArguments(argsList, args)

args.Directory must contains "/memes" args.ShowHidden must be true

Types

This section is empty.

Jump to

Keyboard shortcuts

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