RustFS: Connecting Go to RustFS

This documentation is part of the Quick start guide guide. You can view the complete guide here: How to begin using RustFS for S3-compatible object storage.

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use RustFS Object Storage platform, engineered for reliability and speed. Key benefits include:

  • Unlimited data transfers with no hidden fees.
  • Simple, predictable, and transparent pricing.
  • A custom domain name secured with HTTPS (for example, https://object-storage.your-company.com).
  • A web console and admin API that you can restrict from the internet with a single click.
  • Smooth, one-click updates with no manual intervention required.
  • High performance and security on private, dedicated infrastructure.
  • Available in both 🇪🇺 Europe and 🇺🇸 USA regions.

Optimise 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))
}