Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrModDir = errors.New("out of module directory")
ErrModDir is the error reported trying to get Go module info out of a module directory.
var ErrNoVar = errors.New("nothing to generate")
ErrNoVar is the error reported when there is nothing to generate.
Functions ¶
func TargetPackage ¶
TargetPackage is an utility function to get the package name from its target directory.
TargetPackage checks d existence, reporting a *fs.PathError on failure.
If d does not exist, it is created and its base path is assumed as package name. The d base path is assumed as package name also if d exists but does not contain any *.go file.
If d exists and contains any *.go file, found is reported as true and returns the package name or the error occurred by importing it.
Types ¶
type Config ¶
type Config struct { // Package holds the name of the generated package. // // NOTE // Package value is not parsed and must ben not a path. Package string `json:"package" yaml:"package"` // Target holds the generated package directory path. Relative paths // must be relative to the module root directory. Target string `json:"target" yaml:"target"` // Header holds the generated files header. // // Default: // // Code generated by genenv. DO NOT EDIT. Header string // Variables holds the environment variable key/Spec map. Variables map[string]Spec `json:"variables" yaml:"variables"` // contains filtered or unexported fields }
func ReadConfig ¶
type ModInfo ¶
type ModInfo struct { // Path holds the go module path. // E.g. "github.com/marcozac/genenv" Path string `json:"Path"` // Dir holds the go module directory. // E.g. "/my/module/directory" Dir string `json:"Dir"` // GoMod holds the go.mod file path. // E.g. "/my/module/directory/go.mod" GoMod string `json:"GoMod"` }
func GetModInfo ¶
GetModInfo runs "go list -m -json" and returns a *ModInfo from its output. If there is an error and the command is running out of a module directory, the error reported is ErrModDir.
info, err := GetModInfo() info = &ModInfo{ Path: "github.com/marcozac/genenv", Dir: "/my/module/directory", GoMod: "/my/module/directory/go.mod", }
type Spec ¶
type Spec struct { // Allow holds a list of allowed variable values. // No entries means "any value". Allow []string `json:"allow" yaml:"allow"` // Deny holds a list of denied variable values. // No entries means "nothing". Deny []string `json:"deny" yaml:"deny"` // Required allows to mark an environment variable as required, // returning an error if it has no value. Required bool `json:"required" yaml:"required"` // Doc allows to document the generated function by an optional // godoc comment. // // Default: // // <FuncName> returns the value of the environment variable <Key>. Doc string `json:"doc" yaml:"doc"` // Key holds the environment variable key. // // NOTE: // Do not configure this field: overwritten by initialization. Key string `json:"-" yaml:"-"` // Name holds the name of the function to generate. // // NOTE: // Do not configure this field: overwritten by initialization. Name string `json:"-" yaml:"-"` }
type StrConv ¶
func NewStrConv ¶
func NewStrConv() *StrConv
func (*StrConv) ToPascal ¶
ToPascal returns a pascal-cased copy of str. Any space, hyphen, underscore, comma or dot is removed and the next character is capitalized. Any other character is lowercase.
sc := NewStrConv() s := sc.ToPascal("FOO_-._BAR") // FooBar
Example (Mixed) ¶
sc := NewStrConv() s := sc.ToPascal("FO_O _ -_ B_ --_ _ AR") fmt.Println(s)
Output: FoOBAr
Example (Space) ¶
sc := NewStrConv() s := sc.ToPascal("FOO BAR") fmt.Println(s)
Output: FooBar
Example (Underscore) ¶
sc := NewStrConv() s := sc.ToPascal("FOO_BAR") fmt.Println(s)
Output: FooBar