-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummy.go
62 lines (49 loc) · 1.24 KB
/
dummy.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
package dummy
import (
"errors"
"net/http"
"github.com/bigstack-oss/plane-go/pkg/base/log"
"github.com/bigstack-oss/plane-go/pkg/base/protocol"
"github.com/bigstack-oss/plane-go/pkg/frame/sync/plugin/interact/http/interfacehttp"
"github.com/bigstack-oss/plane-go/pkg/frame/sync/plugin/plug"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
const (
module = "dummy-interact-get"
response = "dummy get response"
)
var (
get = "GET"
)
type DummyHandler struct {
stages []plug.Stager
log *zap.Logger
logf *zap.SugaredLogger
}
func init() {
interfacehttp.Plugins[module] = &DummyHandler{}
}
func (m *DummyHandler) SetConfig() {
m.log = log.GetLogger(module)
m.logf = m.log.Sugar()
}
func (m *DummyHandler) RegisterRouter(router *gin.Engine, method string, path string) error {
switch method {
case get:
router.GET(path, m.get)
default:
m.logf.Errorf("unsupported method(%s) detected in pattern(%s)", method, path)
return errors.New("register unsupported REST method")
}
return nil
}
func (m *DummyHandler) AppendStage(stage string) {
m.stages = append(m.stages, plug.Stagers[stage])
}
func (m *DummyHandler) get(g *gin.Context) {
for _, stage := range m.stages {
stage.Execute(&protocol.Job{})
}
g.JSON(http.StatusOK, response)
}