Skip to content

Instantly share code, notes, and snippets.

@sergsoares
Last active May 15, 2022 15:28
Show Gist options
  • Select an option

  • Save sergsoares/6c6cd50b13926c6d2294ac4bd4bfef47 to your computer and use it in GitHub Desktop.

Select an option

Save sergsoares/6c6cd50b13926c6d2294ac4bd4bfef47 to your computer and use it in GitHub Desktop.
Example in pure go of read a ENV VAR and leaving default value if not exists (In that case already convert from string to integer)
import (
"os"
"strconv"
)
func main() {
tc := 1
if temp := os.Getenv("THREADS"); temp != "" {
number, err := strconv.Atoi(temp)
if err != nil {
panic (err)
}
tc = number
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment