-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #962 from mstgnz/main
New Storage Driver: Minio
- Loading branch information
Showing
12 changed files
with
769 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name-template: 'Minio - v$RESOLVED_VERSION' | ||
tag-template: 'minio/v$RESOLVED_VERSION' | ||
tag-prefix: minio/v | ||
include-paths: | ||
- minio | ||
categories: | ||
- title: '❗ Breaking Changes' | ||
labels: | ||
- '❗ BreakingChange' | ||
- title: '🚀 New' | ||
labels: | ||
- '✏️ Feature' | ||
- title: '🧹 Updates' | ||
labels: | ||
- '🧹 Updates' | ||
- '🤖 Dependencies' | ||
- title: '🐛 Fixes' | ||
labels: | ||
- '☢️ Bug' | ||
- title: '📚 Documentation' | ||
labels: | ||
- '📒 Documentation' | ||
change-template: '- $TITLE (#$NUMBER)' | ||
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. | ||
exclude-contributors: | ||
- dependabot | ||
- dependabot[bot] | ||
version-resolver: | ||
major: | ||
labels: | ||
- 'major' | ||
- '❗ BreakingChange' | ||
minor: | ||
labels: | ||
- 'minor' | ||
- '✏️ Feature' | ||
patch: | ||
labels: | ||
- 'patch' | ||
- '📒 Documentation' | ||
- '☢️ Bug' | ||
- '🤖 Dependencies' | ||
- '🧹 Updates' | ||
default: patch | ||
template: | | ||
$CHANGES | ||
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...minio/v$RESOLVED_VERSION | ||
Thank you $CONTRIBUTORS for making this update possible. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Release Drafter Minio | ||
on: | ||
push: | ||
# branches to consider in the event; optional, defaults to all | ||
branches: | ||
- master | ||
- main | ||
paths: | ||
- 'minio/**' | ||
jobs: | ||
draft_release_minio: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
steps: | ||
- uses: release-drafter/release-drafter@v5 | ||
with: | ||
config-name: release-drafter-minio.yml | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
paths: | ||
- 'minio/**' | ||
pull_request: | ||
paths: | ||
- 'minio/**' | ||
name: "Tests Minio" | ||
jobs: | ||
Tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
go-version: | ||
- 1.19.x | ||
- 1.20.x | ||
- 1.21.x | ||
steps: | ||
- name: Install MinIO | ||
run: | | ||
docker run -d --restart always -p 9000:9000 --name storage-minio -e MINIO_ROOT_USER='minio-user' -e MINIO_ROOT_PASSWORD='minio-password' minio/minio server /data | ||
- name: Fetch Repository | ||
uses: actions/checkout@v3 | ||
- name: Install Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '${{ matrix.go-version }}' | ||
- name: Run Test | ||
run: cd ./minio && go test ./... -v -race |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# Minio | ||
|
||
A Minio storage driver using [minio/minio-go](https://github.com/minio/minio-go). | ||
|
||
**Note: Requires Go 1.19 and above** | ||
|
||
### Table of Contents | ||
- [Signatures](#signatures) | ||
- [Installation](#installation) | ||
- [Examples](#examples) | ||
- [Config](#config) | ||
- [Default Config](#default-config) | ||
|
||
### Signatures | ||
```go | ||
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: | ||
```bash | ||
go get github.com/gofiber/storage/minio | ||
``` | ||
And then run minio on Docker | ||
```bash | ||
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. | ||
```go | ||
import "github.com/gofiber/storage/minio" | ||
``` | ||
|
||
You can use the following possibilities to create a storage: | ||
```go | ||
// 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 | ||
```go | ||
// 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: | ||
```go | ||
// 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 | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package minio | ||
|
||
import ( | ||
"github.com/minio/minio-go/v7" | ||
) | ||
|
||
// 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 | ||
} | ||
|
||
type Credentials struct { | ||
// AccessKeyID is like user-id that uniquely identifies your account. | ||
AccessKeyID string | ||
// SecretAccessKey is the password to your account. | ||
SecretAccessKey string | ||
} | ||
|
||
// 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{}, | ||
} | ||
|
||
// Helper function to set default values | ||
func configDefault(config ...Config) Config { | ||
// Return default config if nothing provided | ||
if len(config) < 1 { | ||
return ConfigDefault | ||
} | ||
|
||
// Override default config | ||
cfg := config[0] | ||
|
||
// Set default values | ||
if cfg.Bucket == "" { | ||
cfg.Bucket = ConfigDefault.Bucket | ||
} | ||
|
||
return cfg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module github.com/gofiber/storage/minio | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/minio/minio-go/v7 v7.0.63 | ||
github.com/stretchr/testify v1.8.4 | ||
github.com/valyala/bytebufferpool v1.0.0 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/dustin/go-humanize v1.0.1 // indirect | ||
github.com/google/uuid v1.3.1 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/compress v1.16.7 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.5 // indirect | ||
github.com/minio/md5-simd v1.1.2 // indirect | ||
github.com/minio/sha256-simd v1.0.1 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/rs/xid v1.5.0 // indirect | ||
github.com/sirupsen/logrus v1.9.3 // indirect | ||
golang.org/x/crypto v0.12.0 // indirect | ||
golang.org/x/net v0.14.0 // indirect | ||
golang.org/x/sys v0.11.0 // indirect | ||
golang.org/x/text v0.12.0 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.