packagemainimport"fmt"funcf()int{fmt.Println("f!")return1}funcgetFavoriteThing()string{return"cookies"}funcmain(){////////////////////////////////// A basic switch////////////////////////////////animal:="pony"switchanimal{case"frog":fmt.Println("Ribbit")case"pony":fmt.Println("Neigh")fallthrough// We use fallthrough to fall through to the next casecase"dog":fmt.Println("Bark")default:fmt.Println("Noise")}///////////////////////////////// Using a simple statement///////////////////////////////switchfave:=getFavoriteThing();fave{case"cookies":// We have access to fave in the switchfmt.Println(fave)default:fmt.Printf("WRONG! Should have been %s",fave)}// We no longer have access to fave out here.///////////////////////////////// You can make function calls in your cases...// As long as the types agree///////////////////////////////i:=1switchi{case0:fmt.Println("Case 0")casef():fmt.Println("Case f()")}/////////////////////////////// By default, a switch will switch on true.// This is an idiomatic alternative to a big if-else chain./////////////////////////////x,y:=42,42switch{casex>y:fmt.Println("Case x > y")casex<y:fmt.Println("Case x < y")default:fmt.Println("Case x == y")}}