-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_api.go
90 lines (82 loc) · 2.58 KB
/
test_api.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
package system
import (
"context"
"fmt"
"github.com/cloudwego/hertz/pkg/app"
"github.com/edufriendchen/hertz-vue-admin/server/global"
"github.com/edufriendchen/hertz-vue-admin/server/middleware"
"github.com/edufriendchen/hertz-vue-admin/server/model/common"
"github.com/edufriendchen/hertz-vue-admin/server/model/common/response"
"go.uber.org/zap"
)
type TestApi struct{}
func (testApi TestApi) GetApiGroupName() string {
return "test"
}
type test struct {
Name string `vd:"len($)>1"`
Age int `vd:"$>0"`
}
// Test GetAllOnlineUser 获取在线用户的列表
func (testApi *TestApi) AddTest(ctx context.Context, c *app.RequestContext) {
fmt.Println("新增测试接口--")
var l test
err := c.BindAndValidate(&l)
fmt.Println(err)
fmt.Println("name", l.Name)
fmt.Println("age", l.Age)
if err != nil {
fmt.Println("绑定失败")
response.FailWithMessage(err.Error(), c)
return
}
if err != nil {
fmt.Println("验证失败")
response.FailWithMessage(err.Error(), c)
return
}
err = middleware.AuthAndRecord(ctx, c, common.ADD, testApi.GetApiGroupName())
if err != nil {
fmt.Println(err.Error())
global.LOG.Error(err.Error(), zap.Error(err))
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithMessage("新增成功", c)
}
// DeleteTest Test GetAllOnlineUser 获取在线用户的列表
func (testApi *TestApi) DeleteTest(ctx context.Context, c *app.RequestContext) {
fmt.Println("删除测试接口--")
err := middleware.AuthAndRecord(ctx, c, common.DELETE, testApi.GetApiGroupName())
if err != nil {
fmt.Println(err.Error())
global.LOG.Error(err.Error(), zap.Error(err))
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithMessage("删除成功", c)
}
// UpdateTest Test GetAllOnlineUser 获取在线用户的列表
func (testApi *TestApi) UpdateTest(ctx context.Context, c *app.RequestContext) {
fmt.Println("修改测试接口--")
err := middleware.AuthAndRecord(ctx, c, common.UPDATE, testApi.GetApiGroupName())
if err != nil {
fmt.Println(err.Error())
global.LOG.Error(err.Error(), zap.Error(err))
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithMessage("修改成功", c)
}
// Test GetAllOnlineUser 获取在线用户的列表
func (testApi *TestApi) GetTest(ctx context.Context, c *app.RequestContext) {
fmt.Println("获取测试接口--")
err := middleware.AuthAndRecord(ctx, c, common.GET, testApi.GetApiGroupName())
if err != nil {
fmt.Println(err.Error())
global.LOG.Error(err.Error(), zap.Error(err))
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithMessage("获取成功", c)
}