-
Notifications
You must be signed in to change notification settings - Fork 3
/
drop.go
50 lines (44 loc) · 894 Bytes
/
drop.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
package main
import (
"errors"
"net/http"
"github.com/gin-gonic/gin"
)
type dropUserReq struct {
Username *string `json:"username"`
}
func (r *dropUserReq) validate() error {
if r.Username == nil {
return errors.New(`username field is required`)
}
return nil
}
func dropUserHandler(c *gin.Context) {
req := dropUserReq{}
if err := c.ShouldBind(&req); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, response{
Error: true,
Message: err.Error(),
})
return
}
if err := req.validate(); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, response{
Error: true,
Message: err.Error(),
})
return
}
cred := getCredential(c)
result, err := execGSQL(
*cred.Username,
*cred.Password,
nil,
"drop user "+*req.Username,
"")
_, err = processOutput(result, err)
c.JSON(200, response{
Error: err != nil,
Message: result,
})
}