skeleton/internal/storage/storage.go
2019-05-14 14:11:03 +02:00

54 lines
938 B
Go

package storage
import (
"fmt"
"github.com/minio/minio-go"
)
// Config contains the configuration for an S3 backend.
type Config struct {
Key string
Secret string
Location string
Bucket string
Endpoint string
SSL bool
}
// Client is a client for an S3 backend.
type Client struct {
config *Config
*minio.Client
}
// New creates a new Client from config
func New(conf *Config) (*Client, error) {
client := &Client{
config: conf,
}
mc, err := minio.New(
conf.Endpoint,
conf.Key,
conf.Secret,
conf.SSL)
if err != nil {
return nil, err
}
client.Client = mc
return client, nil
}
// GetBucketName returns the bucket name stored in the configuration.
func (c *Client) GetBucketName() string {
return c.config.Bucket
}
// RemoteFilename returns the filename a blob should be stored at.
func (c *Client) RemoteFilename(hash string) string {
return fmt.Sprintf("blob/%s/%s", hash[:2], hash)
}