-
Notifications
You must be signed in to change notification settings - Fork 15
/
httpcode.go
80 lines (70 loc) · 1.2 KB
/
httpcode.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
@author: Jason Pang
@desc: http状态码
@date: 2021/11/28
**/
package various
import (
"github.com/gin-gonic/gin"
"net/http"
"time"
)
func Code200(c *gin.Context) {
c.String(http.StatusOK, "ok")
}
func Code500(c *gin.Context) {
panic("1")
c.String(http.StatusOK, "ok")
}
func Code502(c *gin.Context) {
//方案一
/*
package main
import (
"fmt"
"net"
)
func main() {
ln, err := net.Listen("tcp", "127.0.0.1:8082")
if err != nil {
return
}
go func() {
for {
c, err := ln.Accept()
fmt.Println("Accept")
if err != nil {
break
}
c.Close()
}
}()
select {}
}
*/
//方案二
/*
//r.Run(":8082")
server := http.Server{
Addr: ":8082",
WriteTimeout: time.Second * 1,
ReadTimeout: time.Second * 10,
IdleTimeout: time.Second * 10,
Handler: r,
}
server.ListenAndServe()
*/
time.Sleep(time.Second * 2)
c.String(http.StatusOK, "ok")
}
func Code504(c *gin.Context) {
time.Sleep(time.Second * 100)
c.String(http.StatusOK, "ok")
}
func Code503(c *gin.Context) {
c.String(http.StatusOK, "ok")
}
func Code499(c *gin.Context) {
time.Sleep(time.Second * 100)
c.String(http.StatusOK, "ok")
}