HOWTO do things in Go

Exit Program

import (
  "os"
)

func main() {
  os.Exit(1)
}

Get environment variable

import (
  "os"
)

func main() {
  os.Getenv("GITHUB_API_TOKEN")
}

Print to stdout, stderr

import (
  "fmt"
)

func main() {
  fmt.Fprintf(l.stdout(), "[DEBUG] " + out)
  fmt.Fprintf(l.stderr(), "[ERROR] " + err)
}

Print an error message

import (
  "fmt"
  "os"
)

func main() {
  return fmt.Errorf("error: %w", err)
}

// Print to Standard Error
err := f.thisMayError()

if err != nil {
  fmt.Fprintf(os.Stderr, "error: %v\n", err)
}

Int -> Str

import (
  "strconv"
)

func main() {
  var n int = 0
  str := strconv.Itoa(n)

  fmt.Printf("n -> String: %s", str)
}

Time

https://golang.org/src/time/time.go

import (
  "time"
)

// Get time now
func main() {
  time.Now()
}