|
|
@@ -12,6 +12,7 @@ import (
|
|
12
|
12
|
"os"
|
|
13
|
13
|
"strconv"
|
|
14
|
14
|
"strings"
|
|
|
15
|
+ "sync"
|
|
15
|
16
|
)
|
|
16
|
17
|
|
|
17
|
18
|
type accessResponse struct {
|
|
|
@@ -43,23 +44,46 @@ func (c *Access) Run(cli *CLI, version string) error {
|
|
43
|
44
|
return fmt.Errorf("cannot init config: %w", err)
|
|
44
|
45
|
}
|
|
45
|
46
|
|
|
46
|
|
- ipv4 := c.conf.Network.PublicIP.IPv4.Value(nil)
|
|
47
|
|
- ipv6 := c.conf.Network.PublicIP.IPv6.Value(nil)
|
|
|
47
|
+ wg := &sync.WaitGroup{}
|
|
|
48
|
+ resp := &accessResponse{}
|
|
|
49
|
+ resp.Secret.Base64 = c.conf.Secret.Base64()
|
|
|
50
|
+ resp.Secret.Hex = c.conf.Secret.Hex()
|
|
48
|
51
|
|
|
49
|
|
- if ipv4 == nil {
|
|
50
|
|
- ipv4 = c.getIP("tcp4")
|
|
51
|
|
- }
|
|
|
52
|
+ wg.Add(2)
|
|
52
|
53
|
|
|
53
|
|
- if ipv6 == nil {
|
|
54
|
|
- ipv6 = c.getIP("tcp6")
|
|
55
|
|
- }
|
|
|
54
|
+ go func() {
|
|
|
55
|
+ defer wg.Done()
|
|
56
|
56
|
|
|
57
|
|
- resp := accessResponse{
|
|
58
|
|
- IPv4: c.makeURLs(ipv4, cli),
|
|
59
|
|
- IPv6: c.makeURLs(ipv6, cli),
|
|
60
|
|
- }
|
|
61
|
|
- resp.Secret.Base64 = c.conf.Secret.Base64()
|
|
62
|
|
- resp.Secret.Hex = c.conf.Secret.Hex()
|
|
|
57
|
+ ip := c.conf.Network.PublicIP.IPv4.Value(nil)
|
|
|
58
|
+
|
|
|
59
|
+ if ip == nil {
|
|
|
60
|
+ ip = c.getIP("tcp4")
|
|
|
61
|
+ }
|
|
|
62
|
+
|
|
|
63
|
+ if ip != nil {
|
|
|
64
|
+ ip = ip.To4()
|
|
|
65
|
+ }
|
|
|
66
|
+
|
|
|
67
|
+ resp.IPv4 = c.makeURLs(ip, cli)
|
|
|
68
|
+ }()
|
|
|
69
|
+
|
|
|
70
|
+ go func() {
|
|
|
71
|
+ defer wg.Done()
|
|
|
72
|
+
|
|
|
73
|
+ ip := c.conf.Network.PublicIP.IPv4.Value(nil)
|
|
|
74
|
+
|
|
|
75
|
+ if ip == nil {
|
|
|
76
|
+ ip = c.getIP("tcp6")
|
|
|
77
|
+ }
|
|
|
78
|
+
|
|
|
79
|
+ if ip != nil {
|
|
|
80
|
+ ip = ip.To16()
|
|
|
81
|
+ }
|
|
|
82
|
+
|
|
|
83
|
+ resp.IPv6 = c.makeURLs(ip, cli)
|
|
|
84
|
+ }()
|
|
|
85
|
+
|
|
|
86
|
+ wg.Wait()
|
|
63
|
87
|
|
|
64
|
88
|
encoder := json.NewEncoder(os.Stdout)
|
|
65
|
89
|
|
|
|
@@ -78,7 +102,14 @@ func (c *Access) getIP(protocol string) net.IP {
|
|
78
|
102
|
return c.network.DialContext(ctx, protocol, address)
|
|
79
|
103
|
})
|
|
80
|
104
|
|
|
81
|
|
- resp, err := client.Get("https://ifconfig.co") // nolint: noctx
|
|
|
105
|
+ req, err := http.NewRequest(http.MethodGet, "https://ifconfig.co", nil) // nolint: noctx
|
|
|
106
|
+ if err != nil {
|
|
|
107
|
+ panic(err)
|
|
|
108
|
+ }
|
|
|
109
|
+
|
|
|
110
|
+ req.Header.Add("Accept", "text/plain")
|
|
|
111
|
+
|
|
|
112
|
+ resp, err := client.Do(req)
|
|
82
|
113
|
if err != nil {
|
|
83
|
114
|
return nil
|
|
84
|
115
|
}
|