-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.go
38 lines (36 loc) · 1.04 KB
/
parse.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
package main
import (
"fmt"
"net/url"
"strings"
)
func parseInputText(clipboardContent string) ([]Config, error) {
u, err := url.Parse(strings.TrimSpace(clipboardContent))
// if parse is successful, check the schema
if err == nil {
switch u.Scheme {
case "ss", "socks5", "tls", "split":
// try to parse ss url
return []Config{{Transport: u.String()}}, nil
case "https":
// fetch list from remote config
var c []Config
configStrings, err := getDynamicConfig(u.String())
if err != nil {
return []Config{}, err
}
for _, configString := range configStrings {
c = append(c, Config{Transport: configString, Health: 0, TestReports: []*connectivityReport{}})
}
fmt.Printf("Parsed %d configs from remote url\n", len(c))
return c, nil
case "http":
// reject url due to security issue
return []Config{}, fmt.Errorf("not implemented yet")
default:
// reject url due to unknown schema
return []Config{}, fmt.Errorf("not implemented yet")
}
}
return []Config{}, fmt.Errorf("failed to parse input")
}