forked from rai-project/registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
61 lines (55 loc) · 1.25 KB
/
utils.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 registry
import (
"encoding/base64"
"strings"
"github.com/c3sr/config"
"github.com/c3sr/libkv/store"
"github.com/c3sr/utils"
)
func decrypt(s string) string {
q, err := base64.StdEncoding.DecodeString(s)
if err == nil {
s = string(q)
}
if utils.IsEncryptedString(s) {
c, err := utils.DecryptStringBase64(config.App.Secret, s)
if err == nil {
return c
}
}
return s
}
func cleanupEndpoints(endpoints []string) []string {
es := make([]string, len(endpoints))
for ii, e := range endpoints {
es[ii] = strings.TrimLeft(strings.TrimLeft(e, "http://"), "https://")
}
return es
}
func getProvider(s string) store.Backend {
switch strings.ToLower(s) {
case "consul":
return store.CONSUL
case "zk", "zookeeper":
return store.ZK
case "bolt", "boltdb":
return store.BOLTDB
case "etcd":
return store.ETCD
case "mock":
return store.Backend("mock")
default:
return store.ETCD
}
return store.ETCD
}
func cleanup(name string) string {
name = strings.Replace(name, "p3srservices.", "p3sr/services/", -1)
name = strings.Replace(name, "cermineproto.", "p3sr/services/", -1)
name = strings.Replace(name, ".", "/", -1)
name = strings.TrimSuffix(name, "Service")
if !strings.HasPrefix(name, "/") {
name = "/" + name
}
return name
}