-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdriver.go
More file actions
60 lines (51 loc) · 1.51 KB
/
driver.go
File metadata and controls
60 lines (51 loc) · 1.51 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
package driver
import (
"encoding/json"
"fmt"
"strings"
"github.com/dtm-labs/dtmdriver"
"github.com/go-resty/resty/v2"
"github.com/nacos-group/nacos-sdk-go/clients/naming_client"
"github.com/nacos-group/nacos-sdk-go/common/constant"
"github.com/nacos-group/nacos-sdk-go/vo"
)
type config struct {
Addr string
Type string
ClientConfig constant.ClientConfig
InstanceConfig vo.RegisterInstanceParam
}
type springcloudDriver struct {
client naming_client.INamingClient
}
func (d *springcloudDriver) GetName() string {
return "dtm-driver-springcloud"
}
func (d *springcloudDriver) RegisterService(target string, endpoint string) error {
conf := config{}
err := json.Unmarshal([]byte(target), &conf)
if err != nil {
return fmt.Errorf("invalid options: %s error: %w", target, err)
}
if conf.Type == "nacos" {
d.client, err = newNacosClient(strings.Split(conf.Addr, ","), conf.ClientConfig)
if err != nil {
return fmt.Errorf("new nacos client error: %w", err)
}
} else {
return fmt.Errorf("unknown type: %s", conf.Type)
}
return d.registerService(conf.InstanceConfig, endpoint)
}
func (d *springcloudDriver) ParseServerMethod(uri string) (server string, method string, err error) {
return "", "", nil
}
func (d *springcloudDriver) RegisterAddrResolver() {
dtmdriver.Middlewares.HTTP = append(dtmdriver.Middlewares.HTTP, func(c *resty.Client, r *resty.Request) (err error) {
r.URL, err = d.resolveURL(r.URL)
return
})
}
func init() {
dtmdriver.Register(&springcloudDriver{})
}