-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetect.go
More file actions
31 lines (26 loc) · 791 Bytes
/
detect.go
File metadata and controls
31 lines (26 loc) · 791 Bytes
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
// Package cloudsysfs provides a function for detecting the current host's cloud provider, based on the contents of the /sys filesystem.
package cloudsysfs
import "github.com/erichs/cloudsysfs/providers"
var cloudProviders = [...]func(chan<- string){
providers.AWS,
providers.Azure,
providers.DigitalOcean,
providers.GCE,
providers.OpenStack,
}
// Detect tries to detect the current cloud provider a host is using.
// It returns a lowercase string identifying the provider if found, or empty string if none were detected.
func Detect() string {
sysfscheck := make(chan string)
for _, cloud := range cloudProviders {
go cloud(sysfscheck)
}
provider := ""
for i := 0; i < len(cloudProviders); i++ {
v := <-sysfscheck
if v != "" {
provider = v
}
}
return provider
}