-
Notifications
You must be signed in to change notification settings - Fork 255
/
api_parser.go
92 lines (78 loc) · 2.27 KB
/
api_parser.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
package mgr
import (
"errors"
"fmt"
"net/http"
"sort"
"github.com/qiniu/logkit/conf"
"github.com/qiniu/logkit/parser"
. "github.com/qiniu/logkit/parser/config"
. "github.com/qiniu/logkit/utils/models"
"github.com/labstack/echo"
)
type Service struct {
Prefix string
}
var KeySampleLog = "sampleLog"
// PostParseRet 返回值
type PostParseRet struct {
SamplePoints []Data `json:"SamplePoints"`
}
// post /logkit/parser/parse 接受解析请求
func (rs *RestService) PostParse() echo.HandlerFunc {
return func(c echo.Context) error {
parserConfig := conf.MapConf{}
if err := c.Bind(&parserConfig); err != nil {
return RespError(c, http.StatusBadRequest, ErrParseParse, err.Error())
}
parseData, err := ParseData(parserConfig)
se, ok := err.(*StatsError)
if ok {
err = errors.New(se.LastError)
}
if err != nil {
return RespError(c, http.StatusBadRequest, ErrParseParse, fmt.Sprintf("parser error %v", err))
}
return RespSuccess(c, PostParseRet{SamplePoints: parseData})
}
}
// get /logkit/parser/usages 获得解析用途说明
func (rs *RestService) GetParserUsages() echo.HandlerFunc {
return func(c echo.Context) error {
sort.Stable(ModeUsages)
return RespSuccess(c, ModeUsages)
}
}
// get /logkit/parser/tooltips 获取解析用途提示
func (rs *RestService) GetParserTooltips() echo.HandlerFunc {
return func(c echo.Context) error {
sort.Stable(ModeToolTips)
return RespSuccess(c, ModeToolTips)
}
}
// get /logkit/parser/options 获取解析选项
func (rs *RestService) GetParserKeyOptions() echo.HandlerFunc {
return func(c echo.Context) error {
return RespSuccess(c, ModeKeyOptions)
}
}
// get /logkit/parser/samplelogs 获取样例日志
func (rs *RestService) GetParserSampleLogs() echo.HandlerFunc {
return func(c echo.Context) error {
return RespSuccess(c, SampleLogs)
}
}
// POST /logkit/parser/check
func (rs *RestService) PostParserCheck() echo.HandlerFunc {
return func(c echo.Context) error {
reqConf := conf.MapConf{}
if err := c.Bind(&reqConf); err != nil {
return RespError(c, http.StatusBadRequest, ErrParseParse, err.Error())
}
_, err := parser.NewRegistry().NewLogParser(reqConf)
if err != nil {
return RespError(c, http.StatusBadRequest, ErrParseParse, err.Error())
}
return RespSuccess(c, nil)
}
}