Skip to content

Instantly share code, notes, and snippets.

@savishy
Created May 3, 2020 08:46
Show Gist options
  • Save savishy/04277beb3eea60a202b792b4f5c54743 to your computer and use it in GitHub Desktop.
Save savishy/04277beb3eea60a202b792b4f5c54743 to your computer and use it in GitHub Desktop.
Golang Tips and Tricks

Naked Switch Statements


	switch {
	case x > 100:
		fmt.Println("x is very big")
	case x > 10:
		fmt.Println("x is big")
	default:
		fmt.Println("x is small")
	}
  
  

Inline statements within if conditions

a := 11.0
b := 20.0

if frac := a / b; frac > 0.5 {
	fmt.Println("a is more than half of b")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment