-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
58 lines (49 loc) · 1.33 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
package main
import (
"fmt"
"log"
"os"
"strconv"
"strings"
"time"
)
func main() {
config := load_config("config.json")
key, err := os.ReadFile(config.KeyPath)
if err != nil {
log.Fatal(err)
}
config.Instance.SSHPublicKey = string(key)
for {
for n, s := range config.Domains {
if attempt(config, s) {
return
}
if n != len(config.Domains)-1 {
time.Sleep(time.Second * time.Duration(config.DomainSwitch))
}
}
log.Println("Retrying in " + strconv.Itoa(int(config.RetryDelay)) + " seconds...")
time.Sleep(time.Second * time.Duration(config.RetryDelay))
}
}
func attempt(config Config, domain string) bool {
config.Instance.Domain = domain
err := config.Instance.claim()
if err != nil {
if strings.Contains(fmt.Sprint(err), "Out of host capacity.") {
if config.NotifyCapacity {
alert(config.WebhookURL, 0xff0000, "", "Out of capacity in domain: "+config.Instance.Domain)
}
log.Println("Out of capacity in " + config.Instance.Domain)
return false
}
// you're on your own here, good luck
alert(config.WebhookURL, 0xff0000, "<@"+config.DiscordID+">", "Unknown error occurred, check terminal output for more details.")
fmt.Println(err)
return false
} else {
alert(config.WebhookURL, 0x00ff00, "<@"+config.DiscordID+">", "Possible instance claimed! Check OCI panel.")
return true
}
}