structflag

package module
v0.0.0-...-9873f0a Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2016 License: MIT Imports: 7 Imported by: 0

README

structflag

Build Status

A useful Go library for initializing structs based on command line arguments.

Supports automatically generating flags using the flag package.

Documentation

https://godoc.org/github.com/JeremyOT/structflag.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StructToArgs

func StructToArgs(prefix string, v interface{}, ignoredFields ...string) (args []string)

StructToArgs converts a struct into a list of arguments of the form '-field-name=value'. If prefix is not empty, args will take the form '-prefix-field-name=value'. String values are quoted, bool, int and float values are not. Note that not all types supported by StructToArgs may be unpacked by StructToFlags.

A flag:"name" tag may be applied to the struct fields to set a custom field name. If no matching tag is found, structflag will try to use a "json" tag. Otherwise the field name is used as is. Finally, all underscores in the field name are replaced with '-'.

func StructToFlags

func StructToFlags(prefix string, v interface{}, ignoredFields ...string)

StructToFlags registers the fields of a struct with the flag package so they may be set with arguments of the form '-field-name=value'. If prefix is not empty, args will take

A flag:"name,description,defaultValue" tag may be applied to the struct fields to set a custom field name, description and defaultValue. If no matching tag is found, structflag will try to use a "json" tag for a field name. Otherwise the field name is used as is. Finally, all underscores in the field name are replaced with '-'. Default values are parsed using normal string conversion methods for the value type.

Supported field types: bool, int, int64, uint,uint64, float64, time.Duration, string Calling StructToFlags with a struct containing unsupported fields will panic.

Types

This section is empty.

Jump to

Keyboard shortcuts

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