Skip to content

Instantly share code, notes, and snippets.

@gspencerfabian
Created September 8, 2015 04:19
Show Gist options
  • Select an option

  • Save gspencerfabian/402913f3a09ad00a0150 to your computer and use it in GitHub Desktop.

Select an option

Save gspencerfabian/402913f3a09ad00a0150 to your computer and use it in GitHub Desktop.
golang - example switch statement
package main
import (
"fmt"
"os"
"strconv"
)
var arg1 = os.Args[1]
var arg2 = os.Args[2]
var arg3 = os.Args[3]
func main() {
num1, _ := strconv.ParseFloat(arg2, 64)
num2, _ := strconv.ParseFloat(arg3, 64)
switch {
case arg1 == "add":
fmt.Println(num1 + num2)
case arg1 == "subtract":
fmt.Println(num1 - num2)
case arg1 == "multiply":
fmt.Println(num1 * num2)
case arg1 == "divide":
fmt.Println(num1 / num2)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment