Commit 3fa255ca8fc2b4b84295bd847ab499aea245f065
1 parent
774e1d60
Exists in
master
提交
Showing
2 changed files
with
15 additions
and
15 deletions
Show diff stats
src/HttpServer/logic/httpserver.go
| ... | ... | @@ -90,6 +90,21 @@ func QueryAllAccount(w http.ResponseWriter, r *http.Request) { |
| 90 | 90 | |
| 91 | 91 | logger.Info("QueryAllAccount ") |
| 92 | 92 | |
| 93 | + | |
| 94 | + defer func() { | |
| 95 | + //recover() //可以打印panic的错误信息 | |
| 96 | + //fmt.Println(recover()) | |
| 97 | + if err := recover(); err != nil { //产生了panic异常 | |
| 98 | + fmt.Println(err) | |
| 99 | + } | |
| 100 | + | |
| 101 | + }() //别忘了(), 调用此匿名函数 | |
| 102 | + type A struct { | |
| 103 | + a int | |
| 104 | + } | |
| 105 | + var a *A | |
| 106 | + a.a = 1 | |
| 107 | + | |
| 93 | 108 | //先打开文件 |
| 94 | 109 | filename := "./data.txt" |
| 95 | 110 | var f *os.File | ... | ... |
src/HttpServer/main/main.go
| ... | ... | @@ -2,7 +2,6 @@ package main |
| 2 | 2 | |
| 3 | 3 | import ( |
| 4 | 4 | "HttpServer/conf" |
| 5 | - "fmt" | |
| 6 | 5 | "mysql" |
| 7 | 6 | |
| 8 | 7 | "HttpServer/logic" |
| ... | ... | @@ -70,20 +69,6 @@ func main() { |
| 70 | 69 | //time.Sleep(time.Duration(2) * time.Second) |
| 71 | 70 | //logic.Testsendhttp() |
| 72 | 71 | |
| 73 | - defer func() { | |
| 74 | - //recover() //可以打印panic的错误信息 | |
| 75 | - //fmt.Println(recover()) | |
| 76 | - if err := recover(); err != nil { //产生了panic异常 | |
| 77 | - fmt.Println(err) | |
| 78 | - } | |
| 79 | - | |
| 80 | - }() //别忘了(), 调用此匿名函数 | |
| 81 | - type A struct { | |
| 82 | - a int | |
| 83 | - } | |
| 84 | - var a *A | |
| 85 | - a.a = 1 | |
| 86 | - | |
| 87 | 72 | |
| 88 | 73 | select { |
| 89 | 74 | case _ = <-ch: | ... | ... |