Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DjangoDotEnv ¶
DjangoDotEnv reads environment variables from r and stores them in struct dest according to the rules defined by the django-dotenv project https://github.com/jpadilla/django-dotenv/blob/master/dotenv.py. The variables are stored and available within the dest struct.
func DjangoDotEnvFromFile ¶
DjangoDotEnvFromFile reads environment variables from a file with path and stores them in struct dest. See DjangoDotEnv() for further details.
func NodeJSDotEnv ¶
NodeJSDotEnv reads environment variables from a file typically called `.env` according to the rules defined by the NPM package https://www.npmjs.com/package/dotenv.
func NodeJSDotEnvFromFile ¶
NodeJSDotEnvFromFile reads environment variables from a file with path and stores them in struct dest. See NodeJSDotEnv() for further details.
Example ¶
package main import ( "fmt" "path" "github.com/golistic/envs" ) type UserEnv struct { Username string `envVar:"USER"` HomeDir string `envVar:"HOME"` Avatar string `envVar:"AVATAR" default:"🐣"` } func main() { userEnv := &UserEnv{} p := path.Join(".", "_test_data", "js.example.env") if err := envs.NodeJSDotEnvFromFile(userEnv, p); err != nil { fmt.Println("Error:", err) } else { fmt.Printf("Username: %s\n", userEnv.Username) fmt.Printf("HomeDir : %s\n", userEnv.HomeDir) fmt.Printf("Avatar : %s\n", userEnv.Avatar) } }
Output: Username: alice HomeDir : /home/alice Avatar : 🙂️
func OSEnviron ¶
OSEnviron gets variables from the operating system's environment and stores the values in the struct dest.
This function uses Go's os.Environ.
Panics when dest is non-pointer, nil, or not a struct.
Example ¶
package main import ( "fmt" "os" "github.com/golistic/envs" ) type UserEnv struct { Username string `envVar:"USER"` HomeDir string `envVar:"HOME"` Avatar string `envVar:"AVATAR" default:"🐣"` } func main() { userEnv := &UserEnv{} // we have to set the following so test is deterministic _ = os.Setenv("USER", "alice") _ = os.Setenv("HOME", "/Users/alice") if err := envs.OSEnviron(userEnv); err != nil { fmt.Println("Error:", err) } else { fmt.Printf("Username: %s\n", userEnv.Username) fmt.Printf("HomeDir : %s\n", userEnv.HomeDir) fmt.Printf("Avatar : %s\n", userEnv.Avatar) } }
Output: Username: alice HomeDir : /Users/alice Avatar : 🐣
Types ¶
type ErrReadingFile ¶
func (*ErrReadingFile) Error ¶
func (err *ErrReadingFile) Error() string