-
Notifications
You must be signed in to change notification settings - Fork 0
/
switchUse.go
56 lines (47 loc) · 869 Bytes
/
switchUse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"strings"
)
type AppErr struct {
Status int `json:"-"`
Msg string `json:"msg"`
Payload interface{} `json:"payload"`
}
type AppErr2 struct{}
func (e *AppErr2) Error() string {
return "xxx"
}
type AppErr3 struct{}
func switchType(e interface{}) int {
switch body := e.(type) {
case *AppErr:
fmt.Printf("body = %+v\n", body)
return 1
case error:
fmt.Printf("body = %+v\n", body)
return 2
default:
return 3
}
}
func main1() {
fmt.Println(switchType(&AppErr{}))
fmt.Println(switchType(&AppErr2{}))
fmt.Println(switchType(&AppErr3{}))
}
func main2() {
name := "report"
switch {
case "report", "trial_class", "sku":
// TODO
fmt.Println("proxy to telisruby")
case strings.HasPrefix(name, "sku_v2_"):
fmt.Println("sku_v2_")
default:
fmt.Println("default")
}
}
func main() {
main2()
}