RustFS: Connecting Go to RustFS
This documentation is part of the Getting started guide. View the full guide here: How to begin using RustFS for S3-compatible object storage.
👋 Welcome to the Stackhero documentation!
Stackhero provides a ready-to-use RustFS Object Storage platform designed for reliability and speed. Key advantages include:
- Unlimited data transfers with no hidden costs.
- Simple, predictable, and transparent pricing.
- A custom domain name secured with HTTPS (for example, https://object-storage.your-company.com).
- A web console and an admin API that you can close to the internet in one click.
- One-click, seamless updates that require no manual intervention.
- High performance and security on private, dedicated infrastructure.
- Available in both 🇪🇺 Europe and 🇺🇸 USA regions.
Streamline your workflow and reduce setup time: you can deploy Stackhero's RustFS Object Storage hosting in just 5 minutes.
First, install the AWS SDK packages for Go:
go get github.com/aws/aws-sdk-go-v2/aws
go get github.com/aws/aws-sdk-go-v2/credentials
go get github.com/aws/aws-sdk-go-v2/service/s3
Below is an example to connect to RustFS from Go using the AWS SDK:
package main
import (
"context"
"fmt"
"io"
"log"
"strings"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/s3"
)
func main() {
ctx := context.Background()
client := s3.New(s3.Options{
BaseEndpoint: aws.String("https://<XXXXXX>.stackhero-network.com"),
Region: "us-east-1",
Credentials: credentials.NewStaticCredentialsProvider("<ROOT_ACCESS_KEY>", "<ROOT_SECRET_KEY>", ""),
UsePathStyle: true,
})
bucket := aws.String("newbucket")
key := aws.String("testobject")
// Create a bucket
if _, err := client.CreateBucket(ctx, &s3.CreateBucketInput{Bucket: bucket}); err != nil {
log.Fatal(err)
}
// Upload an object
_, err := client.PutObject(ctx, &s3.PutObjectInput{
Bucket: bucket,
Key: key,
Body: strings.NewReader("Hello from RustFS!"),
})
if err != nil {
log.Fatal(err)
}
// Download the object
object, err := client.GetObject(ctx, &s3.GetObjectInput{Bucket: bucket, Key: key})
if err != nil {
log.Fatal(err)
}
defer object.Body.Close()
content, err := io.ReadAll(object.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(content))
}