/
examples.go
137 lines (129 loc) · 3.88 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
134
135
136
137
package dal
import (
"fmt"
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"github.com/swaggo/swag/example/celler/httputil"
)
// Attribute godoc
// @Summary attribute example
// @Description attribute
// @Tags examples
// @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 /v0alpha/examples/attribute [get]
func Attribute() func(c *gin.Context) {
return func(c *gin.Context) {
c.String(http.StatusOK, fmt.Sprintf("enumstring=%s enumint=%s enumnumber=%s string=%s int=%s default=%s",
c.Query("enumstring"),
c.Query("enumint"),
c.Query("enumnumber"),
c.Query("string"),
c.Query("int"),
c.Query("default"),
))
}
}
// CalcSumOfTwo godoc
// @Summary calc example
// @Description plus
// @Tags examples
// @Accept json
// @Produce json
// @Param val1 query int true "used for calc"
// @Param val2 query int true "used for calc"
// @Success 200 {integer} string "answer"
// @Failure 400 {string} string "ok"
// @Failure 404 {string} string "ok"
// @Failure 500 {string} string "ok"
// @Router /v0alpha/examples/calc [get]
func CalcSumOfTwo() func(c *gin.Context) {
return func(c *gin.Context) {
val1, err := strconv.Atoi(c.Query("val1"))
if err != nil {
httputil.NewError(c, http.StatusBadRequest, err)
return
}
val2, err := strconv.Atoi(c.Query("val2"))
if err != nil {
httputil.NewError(c, http.StatusBadRequest, err)
return
}
ans := val1 + val2
c.String(http.StatusOK, "%d", ans)
}
}
// GetAccountIDInGroup godoc
// @Summary path params example
// @Description path params
// @Tags examples
// @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 /v0alpha/examples/groups/{group_id}/accounts/{account_id} [get]
func GetAccountIDInGroup() func(c *gin.Context) {
return func(c *gin.Context) {
groupID, err := strconv.Atoi(c.Param("group_id"))
if err != nil {
httputil.NewError(c, http.StatusBadRequest, err)
return
}
accountID, err := strconv.Atoi(c.Param("account_id"))
if err != nil {
httputil.NewError(c, http.StatusBadRequest, err)
return
}
c.String(http.StatusOK, "group_id=%d account_id=%d", groupID, accountID)
}
}
// UseHeader godoc
// @Summary custome header example
// @Description custome header
// @Tags examples
// @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 /v0alpha/examples/header [get]
func UseHeader() func(c *gin.Context) {
return func(c *gin.Context) {
c.String(http.StatusOK, c.GetHeader("Authorization"))
}
}
// Securities godoc
// @Summary custome header example
// @Description custome header
// @Tags examples
// @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 /v0alpha/examples/securities [get]
func Securities() func(c *gin.Context) {
return func(c *gin.Context) {
}
}