forked from pangpanglabs/echoswagger
/
controller_user.go
118 lines (98 loc) · 3.93 KB
/
controller_user.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
package main
import (
"encoding/xml"
"net/http"
"time"
"github.com/labstack/echo"
"github.com/pangpanglabs/echoswagger"
)
type UserController struct{}
func (c UserController) Init(g echoswagger.ApiGroup) {
g.SetDescription("Operations about user").
SetExternalDocs("Find out more about our store", "http://swagger.io")
type User struct {
X xml.Name `xml:"Users"`
Id int64 `json:"id"`
UserName string `json:"username"`
FirstName string `json:"firstname"`
LastName string `json:"lastname"`
Email string `json:"email"`
Password string `json:"password"`
Phone string `json:"phone"`
UserStatus int32 `json:"userStatus" swagger:"desc(User Status)"`
}
g.POST("", c.Create).
AddParamBody(&User{}, "body", "Created user object", true).
SetOperationId("createUser").
SetDescription("This can only be done by the logged in user.").
SetSummary("Create user")
g.POST("/createWithArray", c.CreateWithArray).
AddParamBody(&[]User{}, "body", "List of user object", true).
SetOperationId("createUsersWithArrayInput").
SetRequestContentType("application/json", "application/xml").
SetSummary("Creates list of users with given input array")
g.POST("/createWithList", c.CreateWithList).
AddParamBody(&[]User{}, "body", "List of user object", true).
SetOperationId("createUsersWithListInput").
SetSummary("Creates list of users with given input array")
type ResponseHeader struct {
XRateLimit int32 `json:"X-Rate-Limit" swagger:"desc(calls per hour allowed by the user)"`
XExpiresAfter time.Time `json:"X-Expires-After" swagger:"desc(date in UTC when token expires)"`
}
g.GET("/login", c.Login).
AddParamQuery("", "username", "The user name for login", true).
AddParamQuery("", "password", "The password for login in clear text", true).
AddResponse(http.StatusOK, "successful operation", "", ResponseHeader{}).
AddResponse(http.StatusBadRequest, "Invalid username/password supplied", nil, nil).
SetOperationId("loginUser").
SetSummary("Logs user into the system")
g.GET("/logout", c.Logout).
SetOperationId("logoutUser").
SetSummary("Logs out current logged in user session")
g.GET("/{username}", c.GetByUsername).
AddParamPath("", "username", "The name that needs to be fetched. Use user1 for testing. ").
AddResponse(http.StatusOK, "successful operation", &User{}, nil).
AddResponse(http.StatusBadRequest, "Invalid username supplied", nil, nil).
AddResponse(http.StatusNotFound, "User not found", nil, nil).
SetOperationId("getUserByName").
SetSummary("Get user by user name")
g.PUT("/{username}", c.UpdateByUsername).
AddParamPath("", "username", "name that need to be updated").
AddParamBody(&User{}, "body", "Updated user object", true).
AddResponse(http.StatusBadRequest, "Invalid user supplied", nil, nil).
AddResponse(http.StatusNotFound, "User not found", nil, nil).
SetOperationId("updateUser").
SetDescription("This can only be done by the logged in user.").
SetSummary("Updated user")
g.DELETE("/{username}", c.DeleteByUsername).
AddParamPath("", "username", "The name that needs to be deleted").
AddResponse(http.StatusBadRequest, "Invalid username supplied", nil, nil).
AddResponse(http.StatusNotFound, "User not found", nil, nil).
SetOperationId("deleteUser").
SetDescription("This can only be done by the logged in user.").
SetSummary("Delete user")
}
func (UserController) Create(c echo.Context) error {
return nil
}
func (UserController) CreateWithArray(c echo.Context) error {
return nil
}
func (UserController) CreateWithList(c echo.Context) error {
return nil
}
func (UserController) Login(c echo.Context) error {
return nil
}
func (UserController) Logout(c echo.Context) error {
return nil
}
func (UserController) GetByUsername(c echo.Context) error {
return nil
}
func (UserController) UpdateByUsername(c echo.Context) error {
return nil
}
func (UserController) DeleteByUsername(c echo.Context) error {
return nil
}