Documentation ¶
Overview ¶
Package arg This is an interceptor dedicated to push flags found to the final schema given by gautocloud. if flags is not a zero value it will override value from schema given by gautocloud. It uses https://github.com/alexflint/go-arg to translate flags into a struct.
Example ¶
// This is only to fake args from console // Normally you don't have to set this option argsOpt := Args([]string{ "app", `--foo=bar`, "--bar", }) argInterceptor := NewArg(argsOpt) type MyConfig struct { Foo string Bar bool Orig string } // Initialize a fake cloud env only for example, normally you should do this in init() function os.Clearenv() os.Setenv("DYNO", "true") // Here we set a value for Orig field from MyConfig schema os.Setenv("CONFIG_ORIG", "<injected by gautocloud>") gautocloud.RegisterConnector(generic.NewConfigGenericConnector(MyConfig{}, argInterceptor)) gautocloud.ReloadConnectors() ////// var config MyConfig err := gautocloud.Inject(&config) if err != nil { panic(err) } // We can see that we have our config altered by flags found fmt.Println(fmt.Sprintf("%#v", config))
Output: arg_test.MyConfig{Foo:"bar", Bar:true, Orig:"<injected by gautocloud>"}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Args ¶
func Args(args []string) optSetter
Args Option to set args to be parsed as flags Default: os.Args
func Config ¶
func Config(config arg.Config) optSetter
Config Option to set arg.Config from https://github.com/alexflint/go-arg Default: arg.Config{}
Types ¶
type ArgInterceptor ¶
type ArgInterceptor struct {
// contains filtered or unexported fields
}
func NewArg ¶
func NewArg(setters ...optSetter) *ArgInterceptor
func (ArgInterceptor) Intercept ¶
func (i ArgInterceptor) Intercept(current, found interface{}) (interface{}, error)
Click to show internal directories.
Click to hide internal directories.