-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransfer.go
More file actions
77 lines (67 loc) · 1.35 KB
/
transfer.go
File metadata and controls
77 lines (67 loc) · 1.35 KB
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
package handler2gin
import (
"errors"
"github.com/danvei233/fchandler2go/core"
"github.com/danvei233/fchandler2go/domain"
"github.com/gin-gonic/gin"
)
type Reflector struct {
h domain.HandlerStandardizer
M domain.MapProvider
}
func NewReflector(M domain.MapProvider) *Reflector {
return &Reflector{M: M}
}
func (r *Reflector) T(h interface{}) gin.HandlerFunc {
//load cfg
r.h = core.NewStandardizer(&h)
var err error
t, InType := r.h.CheckOutputValid(r.M.GetOutputAllowedList())
if !t {
err = errors.New("match output error")
}
t, _ = r.h.CheckInputValid(r.M.GetInputAllowedList())
if !t {
err = errors.New("match input error")
}
return func(c *gin.Context) {
// if there is a dog call back that I failed
if err != nil {
c.String(500, err.Error())
return
}
var res []byte
if InType != nil {
res, err = r.M.TransIn(c)
if err != nil {
c.String(500, err.Error())
return
}
} else {
res = []byte{}
}
// if we don't need we can skip
// use handler
var req []byte
fc, err := r.h.GetStandardHandler()
if err != nil {
c.String(500, err.Error())
return
}
req, err = fc(c, res)
if err != nil {
c.String(500, err.Error())
return
}
err = r.M.TransOut(c, req)
if err != nil {
c.String(500, err.Error())
return
}
return
}
}
//Todo
// err X-Fc-Error-Type
// gin
// 细节对照