forked from swaggo/swag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples.go
133 lines (132 loc) · 4.29 KB
/
examples.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package controller
//// PingExample godoc
//// @Summary ping example
//// @Description do ping
//// @Tags example
//// @Accept json
//// @Produce json
//// @Success 200 {string} string "pong"
//// @Failure 400 {string} string "ok"
//// @Failure 404 {string} string "ok"
//// @Failure 500 {string} string "ok"
//// @Router /examples/ping [get]
//func (c *Controller) PingExample(ctx *gin.Context) {
// ctx.String(http.StatusOK, "pong")
// return
//}
//
//// CalcExample godoc
//// @Summary calc example
//// @Description plus
//// @Tags example
//// @Accept json
//// @Produce json
//// @Param val1 query int true "used for calc"
//// @Param val2 query int true "used for calc"
//// @Success 200 {integer} integer "answer"
//// @Failure 400 {string} string "ok"
//// @Failure 404 {string} string "ok"
//// @Failure 500 {string} string "ok"
//// @Router /examples/calc [get]
//func (c *Controller) CalcExample(ctx *gin.Context) {
// val1, err := strconv.Atoi(ctx.Query("val1"))
// if err != nil {
// httputil.NewError(ctx, http.StatusBadRequest, err)
// return
// }
// val2, err := strconv.Atoi(ctx.Query("val2"))
// if err != nil {
// httputil.NewError(ctx, http.StatusBadRequest, err)
// return
// }
// ans := val1 + val2
// ctx.String(http.StatusOK, "%d", ans)
//}
//
//// PathParamsExample godoc
//// @Summary path params example
//// @Description path params
//// @Tags example
//// @Accept json
//// @Produce json
//// @Param group_id path int true "Group ID"
//// @Param account_id path int true "Account ID"
//// @Success 200 {string} string "answer"
//// @Failure 400 {string} string "ok"
//// @Failure 404 {string} string "ok"
//// @Failure 500 {string} string "ok"
//// @Router /examples/groups/{group_id}/accounts/{account_id} [get]
//func (c *Controller) PathParamsExample(ctx *gin.Context) {
// groupID, err := strconv.Atoi(ctx.Param("group_id"))
// if err != nil {
// httputil.NewError(ctx, http.StatusBadRequest, err)
// return
// }
// accountID, err := strconv.Atoi(ctx.Param("account_id"))
// if err != nil {
// httputil.NewError(ctx, http.StatusBadRequest, err)
// return
// }
// ctx.String(http.StatusOK, "group_id=%d account_id=%d", groupID, accountID)
//}
//
//// HeaderExample godoc
//// @Summary custome header example
//// @Description custome header
//// @Tags example
//// @Accept json
//// @Produce json
//// @Param Authorization header string true "Authentication header"
//// @Success 200 {string} string "answer"
//// @Failure 400 {string} string "ok"
//// @Failure 404 {string} string "ok"
//// @Failure 500 {string} string "ok"
//// @Router /examples/header [get]
//func (c *Controller) HeaderExample(ctx *gin.Context) {
// ctx.String(http.StatusOK, ctx.GetHeader("Authorization"))
//}
//
//// SecuritiesExample godoc
//// @Summary custome header example
//// @Description custome header
//// @Tags example
//// @Accept json
//// @Produce json
//// @Param Authorization header string true "Authentication header"
//// @Success 200 {string} string "answer"
//// @Failure 400 {string} string "ok"
//// @Failure 404 {string} string "ok"
//// @Failure 500 {string} string "ok"
//// @Security ApiKeyAuth
//// @Security OAuth2Implicit[admin, write]
//// @Router /examples/securities [get]
//func (c *Controller) SecuritiesExample(ctx *gin.Context) {
//}
//
//// AttributeExample godoc
//// @Summary attribute example
//// @Description attribute
//// @Tags example
//// @Accept json
//// @Produce json
//// @Param enumstring query string false "string enums" Enums(A, B, C)
//// @Param enumint query int false "int enums" Enums(1, 2, 3)
//// @Param enumnumber query number false "int enums" Enums(1.1, 1.2, 1.3)
//// @Param string query string false "string valid" minlength(5) maxlength(10)
//// @Param int query int false "int valid" mininum(1) maxinum(10)
//// @Param default query string false "string default" default(A)
//// @Success 200 {string} string "answer"
//// @Failure 400 {string} string "ok"
//// @Failure 404 {string} string "ok"
//// @Failure 500 {string} string "ok"
//// @Router /examples/attribute [get]
//func (c *Controller) AttributeExample(ctx *gin.Context) {
// ctx.String(http.StatusOK, fmt.Sprintf("enumstring=%s enumint=%s enumnumber=%s string=%s int=%s default=%s",
// ctx.Query("enumstring"),
// ctx.Query("enumint"),
// ctx.Query("enumnumber"),
// ctx.Query("string"),
// ctx.Query("int"),
// ctx.Query("default"),
// ))
//}