This repository has been archived by the owner on Feb 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (70 loc) · 1.52 KB
/
main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
"time"
"github.com/btjoker/arukas-get/api"
)
const (
// Token Token
Token = ""
// Secret Secret
Secret = ""
// Port ss设置的端口
Port = 8989
// Password ss的密码,
Password = ``
)
func main() {
init := time.Now()
if !resolve() {
fmt.Println("无法写入, 生成失败!")
return
}
fmt.Println("生成成功!")
exec.Command("Shadowsocks.exe").Start()
fmt.Println(time.Since(init))
}
func resolve() bool {
var (
JSON api.Application
configs api.GuiConfig
)
req, _ := http.NewRequest("GET", "https://app.arukas.io/api/containers", nil)
req.Header.Set("Content-Type", "application/vnd.api+json")
req.Header.Set("Accept", "application/vnd.api+json")
req.Header.Set("User-Agent", "地外行星")
// 基本认证
req.SetBasicAuth(Token, Secret)
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatalln(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
if err := json.Unmarshal(body, &JSON); err != nil {
log.Fatalln(err)
}
for _, v1 := range JSON.Data[0].Attributes.PortMappings {
for _, v2 := range v1 {
if v2.ContainerPort == Port {
configs.Add(v2.Host, Password, v2.ServicePort)
}
}
}
file, err := os.Create("gui-config.json")
if err != nil {
log.Fatalln(err)
}
if data, err := configs.Result(); err == nil {
file.Write(data)
return true
}
defer file.Close()
return false
}