Debian Codegraph @

examples/type_assert/type_assert.go

raw symbols SCIP
1 package main
2
3 import (
4 "fmt"
5 "github.com/docopt/docopt-go"
6 )
7
8 func main() {
9 usage := `usage: type_assert [-x] [-y]`
10
11 arguments, err := docopt.ParseDoc(usage)
12 if err != nil {
13 fmt.Println(err)
14 }
15
16 fmt.Println(arguments)
17
18 var x = arguments["-x"].(bool) // type assertion required
19 if x == true {
20 fmt.Println("x is true")
21 }
22
23 y := arguments["-y"] // no type assertion needed
24 if y == true {
25 fmt.Println("y is true")
26 }
27 y2 := arguments["-y"]
28 if y2 == 10 { // this will never be true, a type assertion would have produced a build error
29 fmt.Println("y is 10")
30 }
31 }