From 7ebfab2ae4322eeba01e738ff50089907c8a3c5f Mon Sep 17 00:00:00 2001 From: Nikhil Prabhu Date: Sun, 16 Jul 2023 20:19:50 +0530 Subject: [PATCH] Add detection for Alibaba Cloud --- alibabacloud.go | 13 +++++++++++++ detect.go | 26 +++++++++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 alibabacloud.go 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 }