Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

go build

Install it

go install


Functions 

Example showing error returnFunctions

Code Block
package main

import (
  "fmt"
  "error"
  "math"
)

func main() {
  result, err := sqrt(16)
  
  if err != sum(2,3 nil {
    fmt.Println(err)
  } else {
    fmt.Println(result)
  }
}

func sqrt(x float64) (float64, error ) {
  if x < 0 {
    return 0, errors.New("Undefined for negative numbers")
  }
  return math.Sqrt(x), nil
} 


Commands

CommandDescription
go run <src.go>Run some code
go buildCompile the code. Outputs to local folder. Executable has folder as name.
go installCompiles and places the output in workspace/bin
go env GOPATHOutputs the default workspace folder

...