Documentation
¶
Index ¶
- Constants
- func Bool(name string, def bool) bool
- func CopyFile(sourceFile, toNewFile string) error
- func DoubleQuoteEscape(line string) string
- func Dur(name string, def time.Duration) time.Duration
- func Exec(filenames []string, cmd string, cmdArgs []string) error
- func Float(name string, def float64) float64
- func GoTypeToPHPCode(v interface{}) string
- func HashFileMd5(filePath string) (string, error)
- func Int(name string, def int) int
- func LastErr() error
- func Load(filenames ...string) (err error)
- func Marshal(envMap map[string]string) (string, error)
- func MultiNSInOneFile(fileName, suffix string, nss []string, multiData map[string]map[string]string) error
- func NSSyntax(namespace string) string
- func Overload(filenames ...string) (err error)
- func Parse(r io.Reader) (envMap map[string]string, err error)
- func Read(filenames ...string) (envMap map[string]string, err error)
- func SingleNSInOneFile(fileName, suffix string, data map[string]string) error
- func Str(name, def string) string
- func Unmarshal(str string) (envMap map[string]string, err error)
- func WriteContentIntoEnvFile(content string, filename string) error
- func WriteEnvFile(envMap map[string]string, filename string) error
- func WriteFile(filename, content string, perm os.FileMode) error
Constants ¶
const ( F_ENV = "env" F_INI = "ini" F_PHP = "php" F_YAML = "yaml" F_YML = "yml" F_XML = "xml" F_TXT = "txt" )
const (
FilePerm = 0644
)
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool returns value of environment variable name as a bool. It will return def if environment variable is missing, empty or failed to parse as bool.
func DoubleQuoteEscape ¶
func Dur ¶
Dur returns value of environment variable name as a time.Duration. It will return def if environment variable is missing, empty or failed to parse as a time.Duration.
func Exec ¶
Exec loads env vars from the specified filenames (empty map falls back to default) then executes the cmd specified.
Simply hooks up os.Stdin/err/out to the command and calls Run()
If you want more fine grained control over your command it's recommended that you use `Load()` or `Read()` and the `os/exec` package yourself.
func Float ¶
Float returns value of environment variable name as a float64. It will return def if environment variable is missing, empty or failed to parse as a float64.
func Int ¶
Int returns value of environment variable name as an int. It will return def if environment variable is missing, empty or failed to parse as an int.
func LastErr ¶
func LastErr() error
LastErr returns last error happens while parsing environment variable by any function of this package. Following calls will return nil until new error happens.
func Load ¶
Load will read your env file(s) and load them into ENV for this process.
Call this function as close as possible to the start of your program (ideally in main)
If you call Load without any args it will default to loading .env in the current path ¶
You can otherwise tell it which files to load (there can be more than one) like
godotenv.Load("fileone", "filetwo")
It's important to note that it WILL NOT OVERRIDE an env variable that already exists - consider the .env file to set dev vars or sensible defaults
func Marshal ¶
Marshal outputs the given environment as a dotenv-formatted environment file. Each line is in the format: KEY="VALUE" where VALUE is backslash-escaped.
func MultiNSInOneFile ¶
func MultiNSInOneFile(fileName, suffix string, nss []string, multiData map[string]map[string]string) error
MultiNSInOneFile 将多个NS配置数据写入到一个文件中
func Overload ¶
Overload will read your env file(s) and load them into ENV for this process.
Call this function as close as possible to the start of your program (ideally in main)
If you call Overload without any args it will default to loading .env in the current path ¶
You can otherwise tell it which files to load (there can be more than one) like
godotenv.Overload("fileone", "filetwo")
It's important to note this WILL OVERRIDE an env variable that already exists - consider the .env file to forcefilly set all vars.
func Read ¶
Read all env (with same file loading semantics as Load) but return values as a map rather than automatically writing values into env
func SingleNSInOneFile ¶
SingleNSInOneFile 将单独一个NS配置数据写入一个文件
func Str ¶
Str returns value of environment variable name as a string. It will return def if environment variable is missing or empty.
func WriteContentIntoEnvFile ¶
Write serializes the given environment and writes it to a file
func WriteEnvFile ¶
Write serializes the given environment and writes it to a file
Types ¶
This section is empty.