go-cloud
The Go Cloud Development Kit (Go CDK): A library and tools for open cloud development in Go.
Top Related Projects
This SDK has reached end-of-support. The AWS SDK for Go v2 is available here: https://github.com/aws/aws-sdk-go-v2
This repository is for active development of the Azure SDK for Go. For consumers of the SDK we recommend visiting our public developer docs at:
Pulumi - Infrastructure as Code in any programming language 🚀
DigitalOcean Go API client
Quick Overview
Go Cloud Development Kit (Go CDK) is an open-source project by Google that provides a set of portable Go APIs for common cloud services. It aims to make it easier for developers to write Go applications that can run on multiple cloud platforms without significant code changes, promoting cloud agnosticism and reducing vendor lock-in.
Pros
- Enables writing cloud-agnostic Go applications
- Supports multiple major cloud providers (AWS, GCP, Azure)
- Provides a consistent API across different cloud services
- Simplifies development and testing of cloud applications
Cons
- May have a learning curve for developers already familiar with specific cloud SDKs
- Not all cloud services are supported, and feature parity may vary
- Abstractions might limit access to provider-specific advanced features
- Project is still in active development, so APIs may change
Code Examples
- Opening a blob (file) from cloud storage:
import "gocloud.dev/blob"
ctx := context.Background()
bucket, err := blob.OpenBucket(ctx, "s3://my-bucket?region=us-west-1")
if err != nil {
log.Fatal(err)
}
defer bucket.Close()
data, err := bucket.ReadAll(ctx, "file.txt")
if err != nil {
log.Fatal(err)
}
fmt.Println(string(data))
- Publishing a message to a topic:
import "gocloud.dev/pubsub"
ctx := context.Background()
topic, err := pubsub.OpenTopic(ctx, "gcppubsub://my-project/my-topic")
if err != nil {
log.Fatal(err)
}
defer topic.Shutdown(ctx)
err = topic.Send(ctx, &pubsub.Message{Body: []byte("Hello, World!")})
if err != nil {
log.Fatal(err)
}
- Connecting to a SQL database:
import "gocloud.dev/mysql"
db, err := mysql.Open(ctx, "mysql://username:password@localhost:3306/mydb")
if err != nil {
log.Fatal(err)
}
defer db.Close()
rows, err := db.Query("SELECT * FROM users")
if err != nil {
log.Fatal(err)
}
defer rows.Close()
Getting Started
To start using Go CDK, follow these steps:
-
Install Go CDK:
go get gocloud.dev
-
Import the desired package in your Go code:
import "gocloud.dev/blob" // or import "gocloud.dev/pubsub" // etc.
-
Use the appropriate
Open
function to connect to your cloud service:bucket, err := blob.OpenBucket(ctx, "s3://my-bucket?region=us-west-1")
-
Interact with the cloud service using the provided APIs:
data, err := bucket.ReadAll(ctx, "file.txt")
For more detailed documentation and examples, visit the Go CDK website.
Competitor Comparisons
This SDK has reached end-of-support. The AWS SDK for Go v2 is available here: https://github.com/aws/aws-sdk-go-v2
Pros of aws-sdk-go
- Comprehensive coverage of AWS services
- Well-established and mature SDK with extensive documentation
- Strong community support and regular updates
Cons of aws-sdk-go
- Tightly coupled to AWS, limiting portability
- Steeper learning curve due to its extensive API surface
- Larger codebase and potential for bloat in smaller projects
Code Comparison
aws-sdk-go:
svc := s3.New(session.New())
input := &s3.GetObjectInput{
Bucket: aws.String("my-bucket"),
Key: aws.String("my-key"),
}
result, err := svc.GetObject(input)
go-cloud:
bucket, err := blob.OpenBucket(context.Background(), "s3://my-bucket")
reader, err := bucket.NewReader(context.Background(), "my-key", nil)
defer reader.Close()
The go-cloud example demonstrates its abstraction layer, allowing for easier switching between cloud providers. aws-sdk-go provides direct access to AWS-specific features but requires more setup and AWS-specific code.
go-cloud aims for cloud-agnostic development, while aws-sdk-go offers deep integration with AWS services. Choose based on your project's requirements for portability vs. AWS-specific functionality.
This repository is for active development of the Azure SDK for Go. For consumers of the SDK we recommend visiting our public developer docs at:
Pros of azure-sdk-for-go
- More comprehensive coverage of Azure services
- Regularly updated to align with Azure's latest features
- Provides Azure-specific optimizations and best practices
Cons of azure-sdk-for-go
- Limited to Azure ecosystem, less portable across cloud providers
- Steeper learning curve due to Azure-specific concepts and terminology
- May require more boilerplate code for simple operations
Code Comparison
azure-sdk-for-go:
import "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage"
client := storage.NewAccountsClient(subscriptionID)
client.Authorizer = authorizer
result, err := client.Create(ctx, resourceGroup, accountName, parameters)
go-cloud:
import "gocloud.dev/blob"
bucket, err := blob.OpenBucket(ctx, "azblob://my-bucket")
err = bucket.WriteAll(ctx, "key", []byte("Hello, World!"), nil)
The azure-sdk-for-go example shows direct interaction with Azure services, while go-cloud provides a more abstract interface for cloud-agnostic operations. go-cloud aims for portability across cloud providers, whereas azure-sdk-for-go offers deeper integration with Azure-specific features and services.
Pulumi - Infrastructure as Code in any programming language 🚀
Pros of Pulumi
- Supports multiple programming languages (Python, JavaScript, Go, .NET)
- Offers a unified approach for managing cloud infrastructure across providers
- Provides a state management system for tracking and versioning infrastructure
Cons of Pulumi
- Steeper learning curve for users new to infrastructure-as-code concepts
- Requires additional tooling and setup compared to Go Cloud's library approach
- May have more overhead for simple projects or single-cloud deployments
Code Comparison
Pulumi (TypeScript):
import * as aws from "@pulumi/aws";
const bucket = new aws.s3.Bucket("my-bucket");
export const bucketName = bucket.id;
Go Cloud:
import "gocloud.dev/blob"
bucket, err := blob.OpenBucket(ctx, "s3://my-bucket")
if err != nil {
// Handle error
}
Summary
Pulumi offers a more comprehensive infrastructure-as-code solution with multi-language support, while Go Cloud provides a simpler, Go-specific approach for cloud-agnostic development. Pulumi excels in complex, multi-cloud scenarios, whereas Go Cloud may be more suitable for Go developers seeking portability across cloud providers with minimal setup.
DigitalOcean Go API client
Pros of godo
- Focused specifically on DigitalOcean's API, providing a more tailored experience for DigitalOcean users
- Simpler and more lightweight, making it easier to integrate into existing projects
- More frequent updates and active maintenance due to its narrower scope
Cons of godo
- Limited to DigitalOcean's services, lacking the multi-cloud support offered by go-cloud
- Less comprehensive in terms of overall cloud functionality compared to go-cloud's broader feature set
- Smaller community and ecosystem due to its specialized nature
Code Comparison
godo example:
client := godo.NewFromToken("your-api-token")
droplet, _, err := client.Droplets.Create(&godo.DropletCreateRequest{
Name: "example-droplet",
Region: "nyc3",
Size: "s-1vcpu-1gb",
Image: godo.DropletCreateImage{Slug: "ubuntu-20-04-x64"},
})
go-cloud example:
ctx := context.Background()
bucket, err := blob.OpenBucket(ctx, "s3://my-bucket")
w, err := bucket.NewWriter(ctx, "file.txt", nil)
_, err = w.Write([]byte("Hello, World!"))
err = w.Close()
Both libraries provide Go-idiomatic APIs, but godo focuses on DigitalOcean-specific operations, while go-cloud offers a more abstract, multi-cloud approach.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
The Go Cloud Development Kit (Go CDK)
Write once, run on any cloud âï¸
The Go Cloud Development Kit (Go CDK) allows Go application developers to
seamlessly deploy cloud applications on any combination of cloud providers. It
does this by providing stable, idiomatic interfaces for common uses like storage
and databases. Think database/sql
for cloud products.
Imagine writing this to read from blob storage (like Google Cloud Storage or S3):
ctx := context.Background()
bucket, err := blob.OpenBucket(ctx, "s3://my-bucket")
if err != nil {
return err
}
defer bucket.Close()
blobReader, err := bucket.NewReader(ctx, "my-blob", nil)
if err != nil {
return err
}
and being able to run that code on any cloud you want, avoiding all the ceremony of cloud-specific authorization, tracing, SDKs and all the other code required to make an application portable across cloud platforms.
The project works well with a code generator called
Wire. It creates
human-readable code that only imports the cloud SDKs for services you use. This
allows the Go CDK to grow to support any number of cloud services, without
increasing compile times or binary sizes, and avoiding any side effects from
init()
functions.
You can learn more about the project from our announcement blog post, or our talk at Next 2018:
Installation
# First "cd" into your project directory if you have one to ensure "go get" uses
# Go modules (or not) appropriately. See "go help modules" for more info.
go get gocloud.dev
The Go CDK builds at the latest stable release of Go. Previous Go versions may compile but are not supported.
Documentation
Documentation for the project lives primarily on https://gocloud.dev/, including tutorials.
You can also browse Go package reference on pkg.go.dev.
Project status
The APIs are still in alpha, but we think they are production-ready and are actively looking for feedback from early adopters. If you have comments or questions please open an issue.
At this time we prefer to focus on maintaining the existing APIs and drivers,
and are unlikely to accept new ones into the go-cloud
repository. The modular
nature of the Go CDK makes it simple to host new APIs and drivers for existing
APIs externally, in separate repositories.
If you have a new API or driver that you believe are important and mature enough to be included, feel free to open an issue to discuss this; our default will likely be to suggest starting in a separate repository. We'll also be happy to maintain a list of such external APIs and drivers in this README.
Current features
The Go CDK provides generic APIs for:
- Unstructured binary (blob) storage
- Publish/Subscribe (pubsub)
- Variables that change at runtime (runtimevar)
- Connecting to MySQL (including MariaDB) and PostgreSQL databases (mysql, postgres)
- Server startup and diagnostics: request logging, tracing, and health checking (server)
Contributing
Thank you for your interest in contributing to the Go Cloud Development Kit! :heart:
Everyone is welcome to contribute, whether it's in the form of code, documentation, bug reports, feature requests, or anything else. We encourage you to experiment with the Go CDK and make contributions to help evolve it to meet your needs!
The GitHub repository at google/go-cloud contains some driver implementations for each portable API. We intend to include Google Cloud Platform, Amazon Web Services, and Azure implementations, as well as prominent open source services and at least one implementation suitable for use in local testing. Unfortunately, we cannot support every service directly from the project; however, we encourage contributions in separate repositories.
If you create a repository that implements the Go CDK interfaces for other services, let us know! We would be happy to link to it here and give you a heads-up before making any breaking changes.
See the contributing guide for more details.
Community
This project is covered by the Go Code of Conduct.
Legal disclaimer
The Go CDK is open-source and released under an Apache 2.0 License. Copyright © 2018â2019 The Go Cloud Development Kit Authors.
If you are looking for the website of GoCloud Systems, which is unrelated to the Go CDK, visit https://gocloud.systems.
Top Related Projects
This SDK has reached end-of-support. The AWS SDK for Go v2 is available here: https://github.com/aws/aws-sdk-go-v2
This repository is for active development of the Azure SDK for Go. For consumers of the SDK we recommend visiting our public developer docs at:
Pulumi - Infrastructure as Code in any programming language 🚀
DigitalOcean Go API client
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot