-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv1handler.go
109 lines (88 loc) · 2.91 KB
/
v1handler.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
package main
import (
"encoding/json"
"github.com/valyala/fasthttp"
"github.com/vikebot/vbcore"
"github.com/vikebot/vbrest/vbapi"
"go.uber.org/zap"
)
func v1Test(req *fasthttp.RequestCtx, p string, ctx *zap.Logger) (r interface{}, err error) {
return &simpleResponse{Response: "ok"}, nil
}
func v1UserGet(req *fasthttp.RequestCtx, p string, ctx *zap.Logger) (r interface{}, err error) {
userID, err := authproxy(req, vbcore.PermissionDefault, ctx)
if err != nil {
return nil, err
}
return vbapi.UserGet(userID, ctx)
}
func v1UserGetPublicByID(req *fasthttp.RequestCtx, p string, ctx *zap.Logger) (r interface{}, err error) {
return vbapi.UserGetPublicByID(p[len("/v1/user/get/id/"):], ctx)
}
func v1UserGetPublicByUsername(req *fasthttp.RequestCtx, p string, ctx *zap.Logger) (r interface{}, err error) {
return vbapi.UserGetPublicByUsername(p[len("/v1/user/get/username/"):], ctx)
}
func v1UserUpdate(req *fasthttp.RequestCtx, p string, ctx *zap.Logger) (r interface{}, err error) {
userID, err := authproxy(req, vbcore.PermissionDefault, ctx)
if err != nil {
return nil, err
}
var user vbcore.User
err = json.Unmarshal(req.PostBody(), &user)
if err != nil {
return nil, err
}
err = vbapi.UserUpdate(userID, &user, "", ctx)
if err != nil {
return nil, err
}
return nil, nil
}
func v1RoundActive(req *fasthttp.RequestCtx, p string, ctx *zap.Logger) (r interface{}, err error) {
return vbapi.RoundActive(ctx)
}
func v1RoundJoin(req *fasthttp.RequestCtx, p string, ctx *zap.Logger) (r interface{}, err error) {
userID, err := authproxy(req, vbcore.PermissionDefault, ctx)
if err != nil {
return nil, err
}
err = vbapi.RoundJoin(userID, p[len("/v1/round/join/"):], ctx)
if err != nil {
return nil, err
}
return nil, nil
}
func v1RoundentryActive(req *fasthttp.RequestCtx, p string, ctx *zap.Logger) (r interface{}, err error) {
userID, err := authproxy(req, vbcore.PermissionDefault, ctx)
if err != nil {
return nil, err
}
roundentries, err := vbapi.RoundentryActive(userID, ctx)
if err != nil {
return nil, err
}
return roundentries, nil
}
func v1RoundentryConnectinfo(req *fasthttp.RequestCtx, p string, ctx *zap.Logger) (r interface{}, err error) {
return vbapi.RoundentryConnectinfo(p[len("/v1/roundentry/connectinfo/"):], ctx)
}
func v1RoundentryWatchresolve(req *fasthttp.RequestCtx, p string, ctx *zap.Logger) (r interface{}, err error) {
websocket, err := vbapi.RoundentryWatchresolve(p[len("/v1/roundentry/watchresolve/"):], ctx)
if err != nil {
return nil, err
}
return websocket, nil
}
func v1RegisterConfirm(req *fasthttp.RequestCtx, p string, ctx *zap.Logger) (r interface{}, err error) {
ctx.Debug("", zap.String("json", string(req.PostBody())))
var data vbapi.RegisterConfirmRequest
err = json.Unmarshal(req.PostBody(), &data)
if err != nil {
return nil, err
}
err = vbapi.RegisterConfirm(data, realipFromFasthttp(req), ctx)
if err != nil {
return nil, err
}
return nil, nil
}