util

package
v0.0.0-...-2828018 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	F_ENV  = "env"
	F_INI  = "ini"
	F_PHP  = "php"
	F_YAML = "yaml"
	F_YML  = "yml"
	F_XML  = "xml"
	F_TXT  = "txt"
)
View Source
const (
	FilePerm = 0644
)

Variables

This section is empty.

Functions

func Bool

func Bool(name string, def bool) 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 CopyFile

func CopyFile(sourceFile, toNewFile string) error

CopyFile 复制文件

func DoubleQuoteEscape

func DoubleQuoteEscape(line string) string

func Dur

func Dur(name string, def time.Duration) time.Duration

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

func Exec(filenames []string, cmd string, cmdArgs []string) error

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

func Float(name string, def float64) float64

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 GoTypeToPHPCode

func GoTypeToPHPCode(v interface{}) string

GoTypeToPHPCode 将Go简单数据类型转换为PHP数组

func HashFileMd5

func HashFileMd5(filePath string) (string, error)

HashFileMd5 获取文件md5值

func Int

func Int(name string, def int) 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

func Load(filenames ...string) (err error)

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

func Marshal(envMap map[string]string) (string, error)

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 NSSyntax

func NSSyntax(namespace string) string

func Overload

func Overload(filenames ...string) (err error)

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 Parse

func Parse(r io.Reader) (envMap map[string]string, err error)

Parse reads an env file from io.Reader, returning a map of keys and values.

func Read

func Read(filenames ...string) (envMap map[string]string, err error)

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

func SingleNSInOneFile(fileName, suffix string, data map[string]string) error

SingleNSInOneFile 将单独一个NS配置数据写入一个文件

func Str

func Str(name, def string) string

Str returns value of environment variable name as a string. It will return def if environment variable is missing or empty.

func Unmarshal

func Unmarshal(str string) (envMap map[string]string, err error)

Unmarshal reads an env file from a string, returning a map of keys and values.

func WriteContentIntoEnvFile

func WriteContentIntoEnvFile(content string, filename string) error

Write serializes the given environment and writes it to a file

func WriteEnvFile

func WriteEnvFile(envMap map[string]string, filename string) error

Write serializes the given environment and writes it to a file

func WriteFile

func WriteFile(filename, content string, perm os.FileMode) error

WriteFile 将内容写入文件

Types

This section is empty.

Jump to

Keyboard shortcuts

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