envopts

command module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2022 License: MIT Imports: 15 Imported by: 0

README

envopts

Tests

Provides a code generator for turning env structure into functional options: https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis. Check out the examples directory for general usage.

// FooEnv would describe an environment variable struct parsed using: github.com/caarlos0/env
type FooEnv struct {
	Home         string        `env:"HOME"`
	Port         int           `env:"PORT" envDefault:"3000"`
	Password     string        `env:"PASSWORD,unset"`
	IsProduction bool          `env:"PRODUCTION"`
	Hosts        []string      `env:"HOSTS" envSeparator:":"`
	Duration     time.Duration `env:"DURATION"`
	TempFolder   string        `env:"TEMP_FOLDER" envDefault:"${HOME}/tmp" envExpand:"true"`
}

//go:generate go run github.com/fxlib/envopts -type=FooEnv
// The generate above will generate functional options for each exported struct member with the 'env' tag

backlog

  • Write some more documentation to get the point of this project across. Tell about features:
    • Comment handling
    • EnvDefautl handling
  • We could read the 'required' tag and error when calling ApplyOptions when this is not provided. But it would required to return an extra err value and required options should be passed as separate arguments anyway.
  • Figure out if we need to take care of nested structs of env options
  • Instead of depending on goimport being present to clean up unused or used imports it would be nice if we could do everything from our own binary
  • Add comments to the generated code so developers that read it can follow what is happening. Also for godoc
  • Clean up the codebase, proper error handing in walking
  • Write proper unit tests instead of lazy smoke tests that call the Go command

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Code generated by "envopts -type=FooEnv"; DO NOT EDIT.
Code generated by "envopts -type=FooEnv"; DO NOT EDIT.

Jump to

Keyboard shortcuts

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