A Go library to detect the cloud service provider of a host.
This library is the Go version of my Rust crate cloud-detect, which in itself is inspired by the Python-based cloud-detect and the Go-based satellite modules.
Like these modules, clouddetect
uses a combination of checking vendor files
and metadata endpoints to accurately determine the cloud provider of a host.
While this library is structured similarly to the Rust crate, it follows Go conventions and idioms and is not a direct port.
- Currently, this module supports the identification of the following providers:
- Akamai Cloud (
akamai
) - Amazon Web Services (
aws
) - Microsoft Azure (
azure
) - Google Cloud Platform (
gcp
) - Alibaba Cloud (
alibaba
) - OpenStack (
openstack
) - DigitalOcean (
digitalocean
) - Oracle Cloud Infrastructure (
oci
) - Vultr (
vultr
)
- Akamai Cloud (
- Fast, simple and extensible.
- Real-time console logging using the
zap
module.
Add the library to your project by running:
go get github.com/nikhil-prabhu/clouddetect/v2@latest
Detect the cloud provider and print the result (with default timeout).
package main
import (
"fmt"
"github.com/nikhil-prabhu/clouddetect/v2"
)
func main() {
provider := clouddetect.Detect()
// When tested on AWS:
fmt.Println(provider) // "aws"
// When tested on local/non-supported cloud environment:
fmt.Println(provider) // "unknown"
}
Detect the cloud provider and print the result (with custom timeout and logging).
package main
import (
"fmt"
"github.com/nikhil-prabhu/clouddetect/v2"
"go.uber.org/zap"
)
func main() {
// Use zap.NewDevelopment() for development mode
logger := zap.Must(zap.NewProduction())
defer logger.Sync()
provider := clouddetect.Detect(
clouddetect.WithTimeout(10),
clouddetect.WithLogger(logger),
)
// When tested on AWS:
fmt.Println(provider) // "aws"
// When tested on local/non-supported cloud environment:
fmt.Println(provider) // "unknown"
}
You can also check the list of currently supported cloud providers.
package main
import (
"fmt"
"github.com/nikhil-prabhu/clouddetect/v2"
)
func main() {
fmt.Println(clouddetect.SupportedProviders)
}
For more detailed documentation, please refer to the Module Documentation.
Contributions are welcome and greatly appreciated! If you’d like to contribute to clouddetect, here’s how you can help.
If you encounter a bug, unexpected behavior, or have a feature request, please open an issue. Be sure to include:
- A clear description of the issue.
- Steps to reproduce, if applicable.
- Details about your environment.
If you're submitting a pull request, please ensure the following.
- Your code is formatted using
go fmt
go fmt ./...
- Code lints pass with (use
--fix
to autofix):
golangci-lint run -v --fix
NOTE: To install golangci-lint
, follow the steps outlined
on this page
- Your code contains sufficient unit tests and that all tests pass.
go test ./...
If you find areas in the documentation that are unclear or incomplete, feel free to update the README or module-level documentation. Open a pull request with your improvements.
You can also contribute by reviewing open pull requests. Providing constructive feedback helps maintain a high-quality codebase.