diff --git a/alibabacloud.go b/alibabacloud.go new file mode 100644 index 0000000..86a12c8 --- /dev/null +++ b/alibabacloud.go @@ -0,0 +1,13 @@ +package libdetectcloud + +import ( + "net/http" +) + +func detectAlibabaCloud() string { + resp, err := hc.Get("http://100.100.100.200/latest/") + if err == nil && resp.StatusCode == http.StatusOK { + return "Alibaba Cloud" + } + return "" +} diff --git a/detect.go b/detect.go index 081fd93..2d5122c 100644 --- a/detect.go +++ b/detect.go @@ -11,14 +11,15 @@ var hc = &http.Client{Timeout: 300 * time.Millisecond} // Clouds type type Clouds struct { - Aws string - Azure string - Do string - Gce string - Ost string - Sl string - Vr string - Container string + AlibabaCloud string + Aws string + Azure string + Do string + Gce string + Ost string + Sl string + Vr string + Container string } // Detect function @@ -26,7 +27,11 @@ func Detect() string { if runtime.GOOS != "darwin" { var c Clouds var wg sync.WaitGroup - wg.Add(8) + wg.Add(9) + go func() { + defer wg.Done() + c.AlibabaCloud = detectAlibabaCloud() + }() go func() { defer wg.Done() c.Aws = detectAWS() @@ -61,6 +66,9 @@ func Detect() string { }() wg.Wait() + if c.AlibabaCloud != "" { + return c.AlibabaCloud + } if c.Aws != "" { return c.Aws }