2022-06-03 04:47:58 +08:00
|
|
|
package convert
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/base64"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
2022-06-08 01:50:14 +08:00
|
|
|
"strconv"
|
2022-06-03 04:47:58 +08:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2022-08-07 20:43:11 +08:00
|
|
|
var (
|
|
|
|
encRaw = base64.RawStdEncoding
|
|
|
|
enc = base64.StdEncoding
|
|
|
|
)
|
2022-06-03 04:47:58 +08:00
|
|
|
|
2022-06-15 03:03:26 +08:00
|
|
|
func DecodeBase64(buf []byte) []byte {
|
|
|
|
dBuf := make([]byte, encRaw.DecodedLen(len(buf)))
|
|
|
|
n, err := encRaw.Decode(dBuf, buf)
|
2022-06-03 04:47:58 +08:00
|
|
|
if err != nil {
|
2022-06-15 03:03:26 +08:00
|
|
|
n, err = enc.Decode(dBuf, buf)
|
|
|
|
if err != nil {
|
|
|
|
return buf
|
|
|
|
}
|
2022-06-03 04:47:58 +08:00
|
|
|
}
|
2022-06-15 03:03:26 +08:00
|
|
|
return dBuf[:n]
|
2022-06-03 04:47:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ConvertsV2Ray convert V2Ray subscribe proxies data to clash proxies config
|
|
|
|
func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
|
2022-06-15 03:03:26 +08:00
|
|
|
data := DecodeBase64(buf)
|
2022-06-03 04:47:58 +08:00
|
|
|
|
|
|
|
arr := strings.Split(string(data), "\n")
|
|
|
|
|
|
|
|
proxies := make([]map[string]any, 0, len(arr))
|
|
|
|
names := make(map[string]int, 200)
|
|
|
|
|
|
|
|
for _, line := range arr {
|
|
|
|
line = strings.TrimRight(line, " \r")
|
|
|
|
if line == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
scheme, body, found := strings.Cut(line, "://")
|
|
|
|
if !found {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
scheme = strings.ToLower(scheme)
|
|
|
|
switch scheme {
|
2022-06-08 01:50:14 +08:00
|
|
|
case "hysteria":
|
|
|
|
urlHysteria, err := url.Parse(line)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
query := urlHysteria.Query()
|
|
|
|
name := uniqueName(names, urlHysteria.Fragment)
|
|
|
|
hysteria := make(map[string]any, 20)
|
|
|
|
|
|
|
|
hysteria["name"] = name
|
|
|
|
hysteria["type"] = scheme
|
|
|
|
hysteria["server"] = urlHysteria.Hostname()
|
|
|
|
hysteria["port"] = urlHysteria.Port()
|
2022-06-09 00:22:47 +08:00
|
|
|
hysteria["sni"] = query.Get("peer")
|
2022-06-08 01:50:14 +08:00
|
|
|
hysteria["obfs"] = query.Get("obfs")
|
|
|
|
hysteria["alpn"] = query.Get("alpn")
|
2022-06-09 00:22:47 +08:00
|
|
|
hysteria["auth_str"] = query.Get("auth")
|
2022-06-08 01:50:14 +08:00
|
|
|
hysteria["protocol"] = query.Get("protocol")
|
2022-06-15 23:18:06 +08:00
|
|
|
up := query.Get("up")
|
|
|
|
down := query.Get("down")
|
|
|
|
if up == "" {
|
|
|
|
up = query.Get("upmbps")
|
|
|
|
}
|
|
|
|
if down == "" {
|
|
|
|
down = query.Get("downmbps")
|
|
|
|
}
|
|
|
|
hysteria["down"] = down
|
|
|
|
hysteria["up"] = up
|
2022-06-08 01:50:14 +08:00
|
|
|
hysteria["skip-cert-verify"], _ = strconv.ParseBool(query.Get("insecure"))
|
|
|
|
|
|
|
|
proxies = append(proxies, hysteria)
|
|
|
|
|
2022-06-03 04:47:58 +08:00
|
|
|
case "trojan":
|
|
|
|
urlTrojan, err := url.Parse(line)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-06-08 01:50:14 +08:00
|
|
|
query := urlTrojan.Query()
|
2022-06-03 04:47:58 +08:00
|
|
|
|
|
|
|
name := uniqueName(names, urlTrojan.Fragment)
|
|
|
|
trojan := make(map[string]any, 20)
|
|
|
|
|
|
|
|
trojan["name"] = name
|
|
|
|
trojan["type"] = scheme
|
|
|
|
trojan["server"] = urlTrojan.Hostname()
|
|
|
|
trojan["port"] = urlTrojan.Port()
|
|
|
|
trojan["password"] = urlTrojan.User.Username()
|
|
|
|
trojan["udp"] = true
|
|
|
|
trojan["skip-cert-verify"] = false
|
|
|
|
|
2022-06-08 01:50:14 +08:00
|
|
|
sni := query.Get("sni")
|
2022-06-03 04:47:58 +08:00
|
|
|
if sni != "" {
|
|
|
|
trojan["sni"] = sni
|
|
|
|
}
|
|
|
|
|
2022-06-08 01:50:14 +08:00
|
|
|
network := strings.ToLower(query.Get("type"))
|
2022-06-03 04:47:58 +08:00
|
|
|
if network != "" {
|
|
|
|
trojan["network"] = network
|
|
|
|
}
|
|
|
|
|
2022-06-07 03:17:33 +08:00
|
|
|
switch network {
|
|
|
|
case "ws":
|
2022-06-03 04:47:58 +08:00
|
|
|
headers := make(map[string]any)
|
|
|
|
wsOpts := make(map[string]any)
|
|
|
|
|
|
|
|
headers["User-Agent"] = RandUserAgent()
|
|
|
|
|
2022-06-08 01:50:14 +08:00
|
|
|
wsOpts["path"] = query.Get("path")
|
2022-06-03 04:47:58 +08:00
|
|
|
wsOpts["headers"] = headers
|
|
|
|
|
|
|
|
trojan["ws-opts"] = wsOpts
|
2022-06-07 03:17:33 +08:00
|
|
|
|
|
|
|
case "grpc":
|
|
|
|
grpcOpts := make(map[string]any)
|
2022-06-08 01:50:14 +08:00
|
|
|
grpcOpts["grpc-service-name"] = query.Get("serviceName")
|
2022-06-07 03:17:33 +08:00
|
|
|
trojan["grpc-opts"] = grpcOpts
|
2022-06-03 04:47:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
proxies = append(proxies, trojan)
|
2022-06-07 03:17:33 +08:00
|
|
|
|
|
|
|
case "vless":
|
|
|
|
urlVless, err := url.Parse(line)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-06-08 01:50:14 +08:00
|
|
|
query := urlVless.Query()
|
2022-06-07 03:17:33 +08:00
|
|
|
|
|
|
|
name := uniqueName(names, urlVless.Fragment)
|
|
|
|
vless := make(map[string]any, 20)
|
|
|
|
|
|
|
|
vless["name"] = name
|
|
|
|
vless["type"] = scheme
|
|
|
|
vless["server"] = urlVless.Hostname()
|
|
|
|
vless["port"] = urlVless.Port()
|
|
|
|
vless["uuid"] = urlVless.User.Username()
|
|
|
|
vless["udp"] = true
|
|
|
|
vless["skip-cert-verify"] = false
|
2022-06-21 00:18:34 +08:00
|
|
|
vless["tls"] = false
|
|
|
|
tls := strings.ToLower(query.Get("security"))
|
2022-08-07 20:43:11 +08:00
|
|
|
if strings.HasSuffix(tls, "tls") {
|
2022-06-21 00:18:34 +08:00
|
|
|
vless["tls"] = true
|
|
|
|
}
|
2022-06-08 01:50:14 +08:00
|
|
|
sni := query.Get("sni")
|
2022-06-07 03:17:33 +08:00
|
|
|
if sni != "" {
|
|
|
|
vless["servername"] = sni
|
|
|
|
}
|
|
|
|
|
2022-06-08 01:50:14 +08:00
|
|
|
flow := strings.ToLower(query.Get("flow"))
|
2022-06-07 03:17:33 +08:00
|
|
|
if flow != "" {
|
|
|
|
vless["flow"] = flow
|
|
|
|
}
|
|
|
|
|
2022-06-08 01:50:14 +08:00
|
|
|
network := strings.ToLower(query.Get("type"))
|
2022-06-21 00:18:34 +08:00
|
|
|
fakeType := strings.ToLower(query.Get("headerType"))
|
|
|
|
if fakeType == "http" {
|
|
|
|
network = "http"
|
|
|
|
} else if network == "http" {
|
|
|
|
network = "h2"
|
2022-06-07 03:17:33 +08:00
|
|
|
}
|
2022-06-21 00:18:34 +08:00
|
|
|
vless["network"] = network
|
2022-06-07 03:17:33 +08:00
|
|
|
switch network {
|
2022-06-21 00:18:34 +08:00
|
|
|
case "tcp":
|
|
|
|
if fakeType != "none" {
|
|
|
|
headers := make(map[string]any)
|
|
|
|
httpOpts := make(map[string]any)
|
|
|
|
httpOpts["path"] = []string{"/"}
|
|
|
|
|
|
|
|
if query.Get("host") != "" {
|
|
|
|
headers["Host"] = []string{query.Get("host")}
|
|
|
|
}
|
|
|
|
|
|
|
|
if query.Get("method") != "" {
|
|
|
|
httpOpts["method"] = query.Get("method")
|
|
|
|
}
|
|
|
|
|
|
|
|
if query.Get("path") != "" {
|
|
|
|
httpOpts["path"] = []string{query.Get("path")}
|
|
|
|
}
|
|
|
|
httpOpts["headers"] = headers
|
|
|
|
vless["http-opts"] = httpOpts
|
2022-06-08 01:50:14 +08:00
|
|
|
}
|
2022-06-07 03:17:33 +08:00
|
|
|
|
2022-06-21 00:18:34 +08:00
|
|
|
case "http":
|
2022-06-07 03:17:33 +08:00
|
|
|
headers := make(map[string]any)
|
|
|
|
h2Opts := make(map[string]any)
|
2022-06-21 00:18:34 +08:00
|
|
|
h2Opts["path"] = []string{"/"}
|
|
|
|
if query.Get("path") != "" {
|
|
|
|
h2Opts["path"] = []string{query.Get("path")}
|
|
|
|
}
|
|
|
|
if query.Get("host") != "" {
|
|
|
|
h2Opts["host"] = []string{query.Get("host")}
|
|
|
|
}
|
2022-06-07 03:17:33 +08:00
|
|
|
h2Opts["headers"] = headers
|
|
|
|
vless["h2-opts"] = h2Opts
|
|
|
|
|
|
|
|
case "ws":
|
|
|
|
headers := make(map[string]any)
|
|
|
|
wsOpts := make(map[string]any)
|
2022-06-22 22:18:13 +08:00
|
|
|
headers["User-Agent"] = RandUserAgent()
|
|
|
|
headers["Host"] = query.Get("host")
|
|
|
|
wsOpts["path"] = query.Get("path")
|
2022-06-07 03:17:33 +08:00
|
|
|
wsOpts["headers"] = headers
|
|
|
|
|
|
|
|
vless["ws-opts"] = wsOpts
|
|
|
|
|
|
|
|
case "grpc":
|
|
|
|
grpcOpts := make(map[string]any)
|
2022-06-08 01:50:14 +08:00
|
|
|
grpcOpts["grpc-service-name"] = query.Get("serviceName")
|
2022-06-07 03:17:33 +08:00
|
|
|
vless["grpc-opts"] = grpcOpts
|
|
|
|
}
|
|
|
|
|
|
|
|
proxies = append(proxies, vless)
|
|
|
|
|
2022-06-03 04:47:58 +08:00
|
|
|
case "vmess":
|
2022-06-15 03:03:26 +08:00
|
|
|
dcBuf, err := encRaw.DecodeString(body)
|
2022-06-03 04:47:58 +08:00
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
jsonDc := json.NewDecoder(bytes.NewReader(dcBuf))
|
|
|
|
values := make(map[string]any, 20)
|
|
|
|
|
|
|
|
if jsonDc.Decode(&values) != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
name := uniqueName(names, values["ps"].(string))
|
|
|
|
vmess := make(map[string]any, 20)
|
|
|
|
|
|
|
|
vmess["name"] = name
|
|
|
|
vmess["type"] = scheme
|
|
|
|
vmess["server"] = values["add"]
|
|
|
|
vmess["port"] = values["port"]
|
|
|
|
vmess["uuid"] = values["id"]
|
2022-08-07 20:43:11 +08:00
|
|
|
if alterId, ok := values["aid"]; ok {
|
|
|
|
vmess["alterId"] = alterId
|
|
|
|
} else {
|
|
|
|
vmess["alterId"] = 0
|
|
|
|
}
|
2022-06-03 04:47:58 +08:00
|
|
|
vmess["cipher"] = "auto"
|
|
|
|
vmess["udp"] = true
|
2022-06-21 00:18:34 +08:00
|
|
|
vmess["tls"] = false
|
2022-06-03 04:47:58 +08:00
|
|
|
vmess["skip-cert-verify"] = false
|
|
|
|
|
2022-06-10 03:15:30 +08:00
|
|
|
if values["cipher"] != nil && values["cipher"] != "" {
|
|
|
|
vmess["cipher"] = values["cipher"]
|
|
|
|
}
|
|
|
|
|
2022-06-07 03:17:33 +08:00
|
|
|
sni := values["sni"]
|
|
|
|
if sni != "" {
|
2022-06-10 03:15:30 +08:00
|
|
|
vmess["servername"] = sni
|
2022-06-07 03:17:33 +08:00
|
|
|
}
|
|
|
|
|
2022-06-03 04:47:58 +08:00
|
|
|
network := strings.ToLower(values["net"].(string))
|
2022-06-21 00:18:34 +08:00
|
|
|
if values["type"] == "http" {
|
|
|
|
network = "http"
|
|
|
|
} else if network == "http" {
|
|
|
|
network = "h2"
|
|
|
|
}
|
2022-06-03 04:47:58 +08:00
|
|
|
vmess["network"] = network
|
|
|
|
|
|
|
|
tls := strings.ToLower(values["tls"].(string))
|
2022-06-21 00:18:34 +08:00
|
|
|
if strings.Contains(tls, "tls") {
|
2022-06-03 04:47:58 +08:00
|
|
|
vmess["tls"] = true
|
|
|
|
}
|
|
|
|
|
2022-06-07 03:17:33 +08:00
|
|
|
switch network {
|
|
|
|
case "http":
|
|
|
|
headers := make(map[string]any)
|
|
|
|
httpOpts := make(map[string]any)
|
2022-06-21 00:18:34 +08:00
|
|
|
if values["host"] != "" && values["host"] != nil {
|
|
|
|
headers["Host"] = []string{values["host"].(string)}
|
|
|
|
}
|
|
|
|
httpOpts["path"] = []string{"/"}
|
|
|
|
if values["path"] != "" && values["path"] != nil {
|
|
|
|
httpOpts["path"] = []string{values["path"].(string)}
|
|
|
|
}
|
2022-06-07 03:17:33 +08:00
|
|
|
httpOpts["headers"] = headers
|
|
|
|
|
|
|
|
vmess["http-opts"] = httpOpts
|
|
|
|
|
|
|
|
case "h2":
|
|
|
|
headers := make(map[string]any)
|
|
|
|
h2Opts := make(map[string]any)
|
2022-06-21 00:18:34 +08:00
|
|
|
if values["host"] != "" && values["host"] != nil {
|
|
|
|
headers["Host"] = []string{values["host"].(string)}
|
|
|
|
}
|
2022-06-07 03:17:33 +08:00
|
|
|
|
|
|
|
h2Opts["path"] = values["path"]
|
|
|
|
h2Opts["headers"] = headers
|
|
|
|
|
|
|
|
vmess["h2-opts"] = h2Opts
|
|
|
|
|
|
|
|
case "ws":
|
2022-06-03 04:47:58 +08:00
|
|
|
headers := make(map[string]any)
|
|
|
|
wsOpts := make(map[string]any)
|
2022-06-21 00:18:34 +08:00
|
|
|
wsOpts["path"] = []string{"/"}
|
|
|
|
if values["host"] != "" && values["host"] != nil {
|
2022-06-22 22:18:13 +08:00
|
|
|
headers["Host"] = values["host"].(string)
|
2022-06-10 03:15:30 +08:00
|
|
|
}
|
2022-06-21 00:18:34 +08:00
|
|
|
if values["path"] != "" && values["path"] != nil {
|
2022-06-22 22:18:13 +08:00
|
|
|
wsOpts["path"] = values["path"].(string)
|
2022-06-03 04:47:58 +08:00
|
|
|
}
|
|
|
|
wsOpts["headers"] = headers
|
|
|
|
vmess["ws-opts"] = wsOpts
|
2022-06-07 03:17:33 +08:00
|
|
|
|
|
|
|
case "grpc":
|
|
|
|
grpcOpts := make(map[string]any)
|
|
|
|
grpcOpts["grpc-service-name"] = values["path"]
|
|
|
|
vmess["grpc-opts"] = grpcOpts
|
2022-06-03 04:47:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
proxies = append(proxies, vmess)
|
2022-06-07 03:17:33 +08:00
|
|
|
|
2022-06-03 04:47:58 +08:00
|
|
|
case "ss":
|
|
|
|
urlSS, err := url.Parse(line)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
name := uniqueName(names, urlSS.Fragment)
|
|
|
|
port := urlSS.Port()
|
|
|
|
|
|
|
|
if port == "" {
|
2022-06-15 03:03:26 +08:00
|
|
|
dcBuf, err := encRaw.DecodeString(urlSS.Host)
|
2022-06-03 04:47:58 +08:00
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
urlSS, err = url.Parse("ss://" + string(dcBuf))
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
cipher = urlSS.User.Username()
|
|
|
|
password string
|
|
|
|
)
|
|
|
|
|
|
|
|
if password, found = urlSS.User.Password(); !found {
|
2022-06-22 22:18:13 +08:00
|
|
|
dcBuf, _ := enc.DecodeString(cipher)
|
|
|
|
if !strings.Contains(string(dcBuf), "2022-blake3") {
|
|
|
|
dcBuf, _ = encRaw.DecodeString(cipher)
|
2022-06-03 04:47:58 +08:00
|
|
|
}
|
|
|
|
cipher, password, found = strings.Cut(string(dcBuf), ":")
|
|
|
|
if !found {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ss := make(map[string]any, 20)
|
|
|
|
|
|
|
|
ss["name"] = name
|
|
|
|
ss["type"] = scheme
|
|
|
|
ss["server"] = urlSS.Hostname()
|
|
|
|
ss["port"] = urlSS.Port()
|
|
|
|
ss["cipher"] = cipher
|
|
|
|
ss["password"] = password
|
2022-06-21 00:18:34 +08:00
|
|
|
query := urlSS.Query()
|
2022-06-03 04:47:58 +08:00
|
|
|
ss["udp"] = true
|
2022-06-21 00:18:34 +08:00
|
|
|
if strings.Contains(query.Get("plugin"), "obfs") {
|
|
|
|
obfsParams := strings.Split(query.Get("plugin"), ";")
|
|
|
|
ss["plugin"] = "obfs"
|
|
|
|
ss["plugin-opts"] = map[string]any{
|
|
|
|
"host": obfsParams[2][10:],
|
|
|
|
"mode": obfsParams[1][5:],
|
|
|
|
}
|
|
|
|
}
|
2022-06-03 04:47:58 +08:00
|
|
|
proxies = append(proxies, ss)
|
|
|
|
case "ssr":
|
2022-06-15 03:03:26 +08:00
|
|
|
dcBuf, err := encRaw.DecodeString(body)
|
2022-06-03 04:47:58 +08:00
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// ssr://host:port:protocol:method:obfs:urlsafebase64pass/?obfsparam=urlsafebase64&protoparam=&remarks=urlsafebase64&group=urlsafebase64&udpport=0&uot=1
|
|
|
|
|
|
|
|
before, after, ok := strings.Cut(string(dcBuf), "/?")
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeArr := strings.Split(before, ":")
|
|
|
|
|
|
|
|
if len(beforeArr) != 6 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
host := beforeArr[0]
|
|
|
|
port := beforeArr[1]
|
|
|
|
protocol := beforeArr[2]
|
|
|
|
method := beforeArr[3]
|
|
|
|
obfs := beforeArr[4]
|
|
|
|
password := decodeUrlSafe(urlSafe(beforeArr[5]))
|
|
|
|
|
|
|
|
query, err := url.ParseQuery(urlSafe(after))
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
remarks := decodeUrlSafe(query.Get("remarks"))
|
|
|
|
name := uniqueName(names, remarks)
|
|
|
|
|
|
|
|
obfsParam := decodeUrlSafe(query.Get("obfsparam"))
|
|
|
|
protocolParam := query.Get("protoparam")
|
|
|
|
|
|
|
|
ssr := make(map[string]any, 20)
|
|
|
|
|
|
|
|
ssr["name"] = name
|
|
|
|
ssr["type"] = scheme
|
|
|
|
ssr["server"] = host
|
|
|
|
ssr["port"] = port
|
|
|
|
ssr["cipher"] = method
|
|
|
|
ssr["password"] = password
|
|
|
|
ssr["obfs"] = obfs
|
|
|
|
ssr["protocol"] = protocol
|
|
|
|
ssr["udp"] = true
|
|
|
|
|
|
|
|
if obfsParam != "" {
|
|
|
|
ssr["obfs-param"] = obfsParam
|
|
|
|
}
|
|
|
|
|
|
|
|
if protocolParam != "" {
|
|
|
|
ssr["protocol-param"] = protocolParam
|
|
|
|
}
|
|
|
|
|
|
|
|
proxies = append(proxies, ssr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(proxies) == 0 {
|
|
|
|
return nil, fmt.Errorf("convert v2ray subscribe error: format invalid")
|
|
|
|
}
|
|
|
|
|
|
|
|
return proxies, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func urlSafe(data string) string {
|
|
|
|
return strings.ReplaceAll(strings.ReplaceAll(data, "+", "-"), "/", "_")
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeUrlSafe(data string) string {
|
2022-06-15 03:03:26 +08:00
|
|
|
dcBuf, err := base64.RawURLEncoding.DecodeString(data)
|
2022-06-03 04:47:58 +08:00
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return string(dcBuf)
|
|
|
|
}
|
|
|
|
|
|
|
|
func uniqueName(names map[string]int, name string) string {
|
|
|
|
if index, ok := names[name]; ok {
|
|
|
|
index++
|
|
|
|
names[name] = index
|
2022-06-08 01:50:14 +08:00
|
|
|
name = fmt.Sprintf("%s-%02d", name, index)
|
2022-06-03 04:47:58 +08:00
|
|
|
} else {
|
|
|
|
index = 0
|
|
|
|
names[name] = index
|
|
|
|
}
|
|
|
|
return name
|
|
|
|
}
|