-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdetect.go
98 lines (93 loc) · 1.47 KB
/
detect.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package libdetectcloud
import (
"net/http"
"runtime"
"sync"
"time"
)
var hc = &http.Client{Timeout: 300 * time.Millisecond}
// Clouds type
type Clouds struct {
AlibabaCloud string
Aws string
Azure string
Do string
Gce string
Ost string
Sl string
Vr string
Container string
}
// Detect function
func Detect() string {
if runtime.GOOS != "darwin" {
var c Clouds
var wg sync.WaitGroup
wg.Add(9)
go func() {
defer wg.Done()
c.AlibabaCloud = detectAlibabaCloud()
}()
go func() {
defer wg.Done()
c.Aws = detectAWS()
}()
go func() {
defer wg.Done()
c.Azure = detectAzure()
}()
go func() {
defer wg.Done()
c.Do = detectDigitalOcean()
}()
go func() {
defer wg.Done()
c.Gce = detectGCE()
}()
go func() {
defer wg.Done()
c.Ost = detectOpenStack()
}()
go func() {
defer wg.Done()
c.Sl = detectSoftlayer()
}()
go func() {
defer wg.Done()
c.Vr = detectVultr()
}()
go func() {
defer wg.Done()
c.Container = detectContainer()
}()
wg.Wait()
if c.AlibabaCloud != "" {
return c.AlibabaCloud
}
if c.Aws != "" {
return c.Aws
}
if c.Azure != "" {
return c.Azure
}
if c.Do != "" {
return c.Do
}
if c.Gce != "" {
return c.Gce
}
if c.Ost != "" {
return c.Ost
}
if c.Sl != "" {
return c.Sl
}
if c.Vr != "" {
return c.Vr
}
if c.Container != "" {
return c.Container
}
}
return ""
}