-
Notifications
You must be signed in to change notification settings - Fork 13
/
config.go
61 lines (52 loc) · 1.25 KB
/
config.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
package main
import (
"context"
"encoding/json"
"fmt"
"mosn.io/api"
)
type Config struct {
UniqueId string `json:"unique_id"`
Path string `json:"path"`
Method string `json:"method"`
TragetApp string `json:"target_app"`
ReqMapping ReqMapping `json:"req_mapping"`
RespMapping interface{} `json:"-"`
}
type ReqMapping struct {
Query []*query `json:"query"`
Body *body `json:"body"`
PathParams []*httpPathParam `json:"path_params"`
}
type query struct {
Type string `json:"type"`
Key string `json:"key"`
}
type body struct {
Type string `json:"type"`
}
type httpPathParam struct {
Type string `json:"type"`
Key string `json:"key"`
}
func (t *dubbo2springcloud) getConfig(ctx context.Context, headers api.HeaderMap) (*Config, error) {
details, ok := t.cfg["details"]
if !ok {
return nil, fmt.Errorf("the %s of details is not exist", t.cfg)
}
binfo, err := json.Marshal(details)
if err != nil {
return nil, err
}
var cfgs []*Config
if err := json.Unmarshal(binfo, &cfgs); err != nil {
return nil, err
}
method, _ := headers.Get("method")
for _, cfg := range cfgs {
if cfg.UniqueId == method {
return cfg, nil
}
}
return nil, fmt.Errorf("config is not exist")
}