minio

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2023 License: MIT Imports: 10 Imported by: 0

README


id: minio title: Minio

Release Discord Test Security Linter

Minio

A Minio storage driver using minio/minio-go.

Note: Requires Go 1.19 and above

Table of Contents

Signatures

func New(config ...Config) Storage
func (s *Storage) Get(key string) ([]byte, error)
func (s *Storage) Set(key string, val []byte, exp time.Duration) error
func (s *Storage) Delete(key string) error
func (s *Storage) Reset() error
func (s *Storage) Close() error
func (s *Storage) CheckBucket() error
func (s *Storage) CreateBucket() error
func (s *Storage) RemoveBucket() error
func (s *Storage) Conn() *minio.Client

Installation

Install the Minio implementation:

go get github.com/gofiber/storage/minio

And then run minio on Docker

docker run -d --restart always -p 9000:9000 -p 9001:9001 --name storage-minio --volume=minio:/var/lib/minio -e MINIO_ROOT_USER='minio-user' -e MINIO_ROOT_PASSWORD='minio-password' minio/minio server --console-address ":9001" /var/lib/minio

Examples

Import the storage package.

import "github.com/gofiber/storage/minio"

You can use the following possibilities to create a storage:

// Initialize default config
store := minio.New()

// Initialize custom config
store := minio.New(minio.Config{
    Bucket:   "fiber-bucket",
    Endpoint: "localhost:9000",
    Credentials: Credentials{
        AccessKeyID:     "minio-user",
        SecretAccessKey: "minio-password",
    },
})

Config

// Config defines the config for storage.
type Config struct {
    // Bucket
    // Default fiber-bucket
    Bucket string
    
    // Endpoint is a host name or an IP address
    Endpoint string
    
    // Region Set this value to override region cache
    // Optional
    Region string
    
    // Token Set this value to provide x-amz-security-token (AWS S3 specific)
    // Optional, Default is false
    Token string
    
    // Secure If set to true, https is used instead of http.
    // Default is false
    Secure bool
    
    // Reset clears any existing keys in existing Bucket
    // Optional. Default is false
    Reset bool
    
    // Credentials Minio access key and Minio secret key.
    // Need to be defined
    Credentials Credentials
    
    // GetObjectOptions Options for GET requests specifying additional options like encryption, If-Match
    GetObjectOptions minio.GetObjectOptions
    
    // PutObjectOptions
    // Allows user to set optional custom metadata, content headers, encryption keys and number of threads for multipart upload operation.
    PutObjectOptions minio.PutObjectOptions
    
    // ListObjectsOptions Options per to list objects
    ListObjectsOptions minio.ListObjectsOptions
    
    // RemoveObjectOptions Allows user to set options
    RemoveObjectOptions minio.RemoveObjectOptions
}

Default Config

The default configuration lacks Bucket, Region, and Endpoint which are all required and must be overwritten:

// ConfigDefault is the default config
var ConfigDefault = Config{
    Bucket:              "fiber-bucket",
    Endpoint:            "",
    Region:              "",
    Token:               "",
    Secure:              false,
    Reset:               false,
    Credentials:         Credentials{},
    GetObjectOptions:    minio.GetObjectOptions{},
    PutObjectOptions:    minio.PutObjectOptions{},
    ListObjectsOptions:  minio.ListObjectsOptions{},
    RemoveObjectOptions: minio.RemoveObjectOptions{},
}
type Credentials struct {
    AccessKeyID     string
    SecretAccessKey string
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{
	Bucket:              "fiber-bucket",
	Endpoint:            "",
	Region:              "",
	Token:               "",
	Secure:              false,
	Reset:               false,
	Credentials:         Credentials{},
	GetObjectOptions:    minio.GetObjectOptions{},
	PutObjectOptions:    minio.PutObjectOptions{},
	ListObjectsOptions:  minio.ListObjectsOptions{},
	RemoveObjectOptions: minio.RemoveObjectOptions{},
}

ConfigDefault is the default config

Functions

This section is empty.

Types

type Config

type Config struct {
	// Bucket
	// Default fiber-bucket
	Bucket string

	// Endpoint is a host name or an IP address
	Endpoint string

	// Region Set this value to override region cache
	// Optional
	Region string

	// Token Set this value to provide x-amz-security-token (AWS S3 specific)
	// Optional, Default is false
	Token string

	// Secure If set to true, https is used instead of http.
	// Default is false
	Secure bool

	// Reset clears any existing keys in existing Bucket
	// Optional. Default is false
	Reset bool

	// Credentials Minio access key and Minio secret key.
	// Need to be defined
	Credentials Credentials

	// GetObjectOptions Options for GET requests specifying additional options like encryption, If-Match
	GetObjectOptions minio.GetObjectOptions

	// PutObjectOptions
	// Allows user to set optional custom metadata, content headers, encryption keys and number of threads for multipart upload operation.
	PutObjectOptions minio.PutObjectOptions

	// ListObjectsOptions Options per to list objects
	ListObjectsOptions minio.ListObjectsOptions

	// RemoveObjectOptions Allows user to set options
	RemoveObjectOptions minio.RemoveObjectOptions
}

Config defines the config for storage.

type Credentials

type Credentials struct {
	// AccessKeyID is like user-id that uniquely identifies your account.
	AccessKeyID string
	// SecretAccessKey is the password to your account.
	SecretAccessKey string
}

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

Storage interface that is implemented by storage providers

func New

func New(config ...Config) *Storage

New creates a new storage

func (*Storage) CheckBucket

func (s *Storage) CheckBucket() error

CheckBucket Check to see if bucket already exists

func (*Storage) Close

func (s *Storage) Close() error

Close the storage

func (*Storage) Conn

func (s *Storage) Conn() *minio.Client

Conn Return minio client

func (*Storage) CreateBucket

func (s *Storage) CreateBucket() error

CreateBucket Bucket not found so Make a new bucket

func (*Storage) Delete

func (s *Storage) Delete(key string) error

Delete entry by key

func (*Storage) Get

func (s *Storage) Get(key string) ([]byte, error)

Get value by key

func (*Storage) RemoveBucket

func (s *Storage) RemoveBucket() error

RemoveBucket Bucket remove if bucket is empty

func (*Storage) Reset

func (s *Storage) Reset() error

Reset all entries, including unexpired

func (*Storage) Set

func (s *Storage) Set(key string, val []byte, exp time.Duration) error

Set key with value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL