Documentation ¶
Overview ¶
Package varexpr provides some commonly ENV var parse functions.
parse env value, allow expressions:
${VAR_NAME} Only var name ${VAR_NAME | default} With default value, if value is empty. ${VAR_NAME | ?error} With error on value is empty.
Examples:
only key - "${SHELL}" with default - "${NotExist | defValue}" multi key - "${GOPATH}/${APP_ENV | prod}/dir"
Index ¶
Constants ¶
View Source
const ( // SepChar separator char split var name and default value SepChar = "|" VarLeft = "${" // default var left format chars VarRight = "}" // default var right format chars )
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse parse ENV var value from input string, support default value.
Format:
${var_name} Only var name ${var_name | default} With default value ${var_name | ?error} With error on value is empty.
Types ¶
type ParseOpts ¶
type ParseOpts struct { // Getter Env value provider func. Getter func(string) string // ParseFn custom parse expr func. expr like "${SHELL}" "${NotExist|defValue}" ParseFn func(string) (string, error) // Regexp custom expression regex. Regexp *regexp.Regexp // var format chars for expression. // default left="${", right="}" VarLeft, VarRight string }
ParseOpts parse options for ParseValue
Click to show internal directories.
Click to hide internal directories.