Golang Notes

From Federal Burro of Information
Revision as of 15:14, 23 February 2020 by David (talk | contribs) (Created page with "== Questions == import prefixes what ar ethye: * nothing * "." * "_" == Grab bag == === Environment Variables === https://stackoverflow.com/questions/40326540/how-to-ass...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Questions

import prefixes what ar ethye:

  • nothing
  • "."
  • "_"

Grab bag

Environment Variables

https://stackoverflow.com/questions/40326540/how-to-assign-default-value-if-env-var-is-empty

func getenv(key, fallback string) string {
    value := os.Getenv(key)
    if len(value) == 0 {
        return fallback
    }
    return value
}
func getEnv(key, fallback string) string {
    if value, ok := os.LookupEnv(key); ok {
        return value
    }
    return fallback
}