Compare commits

...

67 Commits

Author SHA1 Message Date
RW
629c25208d Merge pull request #978 from iredmail/main
s3: New methods: CreateBucket, DeleteBucket, SetWithChecksum.
2023-09-07 09:19:10 +02:00
Zhang Huangbin
bf6aa0132c Typo 2023-09-07 10:17:38 +08:00
Zhang Huangbin
4dfe51aa01 Fix incorrect checksum (base64 encoded).
Create bucket in unittest instead of GitHub Actions.
2023-09-06 08:45:46 +08:00
Zhang Huangbin
e735c69371 S3: Add RequestTimeout in unittest. 2023-09-05 17:34:55 +08:00
Zhang Huangbin
ae41d2f5c1 Init testStore in init(). 2023-09-05 17:17:31 +08:00
Zhang Huangbin
dc00bab703 Init testStore in first load test file. 2023-09-05 17:07:43 +08:00
Zhang Huangbin
d06fbfc7f3 Fix incorrect sum. 2023-09-05 16:47:36 +08:00
Zhang Huangbin
e09d83368c Fix incorrect sum. 2023-09-05 16:39:19 +08:00
Zhang Huangbin
1ddcc7b3fc Add example in README.
Use `map[string][]byte` instead of `map[string]string`.
2023-09-05 16:27:09 +08:00
RW
db6c457d5c Merge branch 'main' into main 2023-09-05 10:21:09 +02:00
RW
1e3b3f6a5e Merge pull request #977 from gofiber/dependabot/github_actions/actions/checkout-4
Bump actions/checkout from 3 to 4
2023-09-05 10:20:48 +02:00
Zhang Huangbin
26c755f312 New: SetWithChecksum. 2023-09-05 16:01:32 +08:00
dependabot[bot]
095dbdbf59 Bump actions/checkout from 3 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-05 06:16:40 +00:00
RW
f9a87273bb Merge pull request #962 from mstgnz/main
New Storage Driver: Minio
2023-09-05 08:15:29 +02:00
Juan Calderon-Perez
b6dbad7d88 Update test-minio.yml 2023-09-04 17:42:12 -04:00
Juan Calderon-Perez
8400db5161 Update test-minio.yml 2023-09-04 17:34:35 -04:00
Mesut GENEZ
2e2f6ca4de Merge branch 'main' into main 2023-09-04 11:06:33 +03:00
RW
04d063e759 Merge pull request #976 from gofiber/dependabot/go_modules/dynamodb/github.com/aws/aws-sdk-go-v2/config-1.18.38
Bump github.com/aws/aws-sdk-go-v2/config from 1.18.37 to 1.18.38 in /dynamodb
2023-09-04 09:56:48 +02:00
dependabot[bot]
e50171cdf4 Bump github.com/aws/aws-sdk-go-v2/config in /dynamodb
Bumps [github.com/aws/aws-sdk-go-v2/config](https://github.com/aws/aws-sdk-go-v2) from 1.18.37 to 1.18.38.
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/config/v1.18.37...config/v1.18.38)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go-v2/config
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-04 07:55:01 +00:00
RW
ffd79887c1 Merge pull request #973 from gofiber/dependabot/go_modules/dynamodb/github.com/aws/aws-sdk-go-v2/credentials-1.13.36
Bump github.com/aws/aws-sdk-go-v2/credentials from 1.13.35 to 1.13.36 in /dynamodb
2023-09-04 09:54:03 +02:00
dependabot[bot]
994023df1e Bump github.com/aws/aws-sdk-go-v2/credentials in /dynamodb
Bumps [github.com/aws/aws-sdk-go-v2/credentials](https://github.com/aws/aws-sdk-go-v2) from 1.13.35 to 1.13.36.
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/credentials/v1.13.35...credentials/v1.13.36)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go-v2/credentials
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-04 07:53:56 +00:00
RW
e8756d084b Merge pull request #972 from gofiber/dependabot/go_modules/s3/github.com/aws/aws-sdk-go-v2/feature/s3/manager-1.11.82
Bump github.com/aws/aws-sdk-go-v2/feature/s3/manager from 1.11.81 to 1.11.82 in /s3
2023-09-04 09:52:45 +02:00
dependabot[bot]
919f7f5ae7 Bump github.com/aws/aws-sdk-go-v2/feature/s3/manager in /s3
Bumps [github.com/aws/aws-sdk-go-v2/feature/s3/manager](https://github.com/aws/aws-sdk-go-v2) from 1.11.81 to 1.11.82.
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/feature/s3/manager/v1.11.81...feature/s3/manager/v1.11.82)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go-v2/feature/s3/manager
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-04 07:51:18 +00:00
RW
f98f6ff9e0 Merge pull request #971 from gofiber/dependabot/go_modules/rueidis/github.com/redis/rueidis-1.0.17
Bump github.com/redis/rueidis from 1.0.16 to 1.0.17 in /rueidis
2023-09-04 09:22:20 +02:00
dependabot[bot]
b70ea3d72a Bump github.com/redis/rueidis from 1.0.16 to 1.0.17 in /rueidis
Bumps [github.com/redis/rueidis](https://github.com/redis/rueidis) from 1.0.16 to 1.0.17.
- [Release notes](https://github.com/redis/rueidis/releases)
- [Commits](https://github.com/redis/rueidis/compare/v1.0.16...v1.0.17)

---
updated-dependencies:
- dependency-name: github.com/redis/rueidis
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-04 07:20:19 +00:00
mstgnz
6eba76bd26 fix bytebufferpool 2023-09-03 11:09:44 +03:00
Mesut GENEZ
fee5f98406 Merge branch 'main' into main 2023-09-02 14:36:55 +03:00
René Werner
551552f67f add memory release drafter workflow 2023-09-01 11:22:20 +02:00
RW
6cff923227 Merge pull request #969 from gofiber/dependabot/go_modules/mssql/github.com/microsoft/go-mssqldb-1.6.0
Bump github.com/microsoft/go-mssqldb from 1.5.0 to 1.6.0 in /mssql
2023-09-01 09:32:52 +02:00
dependabot[bot]
1399f55ed4 Bump github.com/microsoft/go-mssqldb from 1.5.0 to 1.6.0 in /mssql
Bumps [github.com/microsoft/go-mssqldb](https://github.com/microsoft/go-mssqldb) from 1.5.0 to 1.6.0.
- [Release notes](https://github.com/microsoft/go-mssqldb/releases)
- [Changelog](https://github.com/microsoft/go-mssqldb/blob/main/CHANGELOG.md)
- [Commits](https://github.com/microsoft/go-mssqldb/compare/v1.5.0...v1.6.0)

---
updated-dependencies:
- dependency-name: github.com/microsoft/go-mssqldb
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-01 07:31:00 +00:00
mstgnz
79fdc2ef78 fix get 2023-08-31 14:06:12 +03:00
Mesut GENEZ
f4a12a2a3b Merge branch 'main' into main 2023-08-29 18:53:51 +03:00
mstgnz
edf7bf23e3 added yo bytebufferpool 2023-08-29 18:53:03 +03:00
mstgnz
1887a32ca2 update credentials key name 2023-08-29 18:44:15 +03:00
RW
a1405af086 Merge pull request #965 from gofiber/dependabot/go_modules/dynamodb/github.com/aws/aws-sdk-go-v2/config-1.18.37
Bump github.com/aws/aws-sdk-go-v2/config from 1.18.36 to 1.18.37 in /dynamodb
2023-08-28 09:34:34 +02:00
dependabot[bot]
de487d56be Bump github.com/aws/aws-sdk-go-v2/config in /dynamodb
Bumps [github.com/aws/aws-sdk-go-v2/config](https://github.com/aws/aws-sdk-go-v2) from 1.18.36 to 1.18.37.
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/config/v1.18.36...config/v1.18.37)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go-v2/config
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-08-28 07:32:40 +00:00
RW
5fd9819f5f Merge pull request #963 from gofiber/dependabot/go_modules/s3/github.com/aws/aws-sdk-go-v2/feature/s3/manager-1.11.81
Bump github.com/aws/aws-sdk-go-v2/feature/s3/manager from 1.11.80 to 1.11.81 in /s3
2023-08-28 09:31:16 +02:00
dependabot[bot]
b86255479c Bump github.com/aws/aws-sdk-go-v2/feature/s3/manager in /s3
Bumps [github.com/aws/aws-sdk-go-v2/feature/s3/manager](https://github.com/aws/aws-sdk-go-v2) from 1.11.80 to 1.11.81.
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/feature/s3/manager/v1.11.80...feature/s3/manager/v1.11.81)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go-v2/feature/s3/manager
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-08-28 07:29:58 +00:00
mstgnz
67218b0d19 bucket check control removed and update test 2023-08-26 18:49:16 +03:00
mstgnz
cdad22386e update comment 2023-08-26 18:30:00 +03:00
mstgnz
cb6a705473 Update README 2023-08-26 18:28:19 +03:00
mstgnz
e0523db53d update comment for CheckBucket 2023-08-26 12:18:56 +03:00
mstgnz
c49bca76d7 change to default bucket name - fiber-bucket 2023-08-26 12:16:49 +03:00
mstgnz
3d598445e3 updated test for key not in get requests 2023-08-25 19:57:39 +03:00
mstgnz
949c597508 definitions added 2023-08-25 18:03:10 +03:00
mstgnz
ca32702aa0 Update README 2023-08-25 17:43:44 +03:00
mstgnz
0ccc5d3faa UPDATE README 2023-08-23 17:25:02 +03:00
mstgnz
4c8f4dcdfc fix minio test 2023-08-23 17:19:40 +03:00
mstgnz
d64fa185db fixed test 2023-08-23 17:18:11 +03:00
mstgnz
cd33dc926f test fixed 2023-08-23 17:13:06 +03:00
mstgnz
fd63105282 min go version supported added to README 2023-08-23 17:08:24 +03:00
mstgnz
dda7fcf987 The Reset flag added to New flag 2023-08-23 17:01:51 +03:00
mstgnz
b597a36454 The stretchr/testify package was used for testing 2023-08-23 16:56:36 +03:00
mstgnz
b2636aa4c1 Merge branch 'main' of github.com:mstgnz/fiber-storage 2023-08-23 16:21:21 +03:00
mstgnz
b3fe37dd3d change go version 2023-08-23 16:19:47 +03:00
Mesut GENEZ
d62aeb54b9 Merge branch 'main' into main 2023-08-23 16:16:05 +03:00
mstgnz
dab578a096 gosec 2023-08-23 16:15:35 +03:00
mstgnz
68fe393de4 minio drafter 2023-08-23 16:01:10 +03:00
mstgnz
4493457cfa minio test 2023-08-23 15:59:24 +03:00
mstgnz
5b49d3629c added to minio gosec and depeddabot and drafter 2023-08-23 14:58:52 +03:00
mstgnz
244330f96e Added to Minio storage 2023-08-23 14:44:24 +03:00
mstgnz
7f002b3158 go mod tidy 2023-08-23 14:33:10 +03:00
mstgnz
d3d3a58f6e Added Conn method to return the Minio instance 2023-08-23 14:29:49 +03:00
Mesut GENEZ
bec8bb64e1 Merge branch 'main' into main 2023-08-23 14:22:05 +03:00
mstgnz
580a711cb1 Fix README 2023-08-23 14:17:00 +03:00
mstgnz
23de4dd79e Fix README 2023-08-23 13:31:56 +03:00
mstgnz
21eb34fec7 minio 2023-08-23 13:25:32 +03:00
51 changed files with 1073 additions and 156 deletions

View File

@@ -68,6 +68,12 @@ updates:
- "🤖 Dependencies"
schedule:
interval: "daily"
- package-ecosystem: "gomod"
directory: "/minio/" # Location of package manifests
labels:
- "🤖 Dependencies"
schedule:
interval: "daily"
- package-ecosystem: "gomod"
directory: "/mongodb/" # Location of package manifests
labels:

50
.github/release-drafter-minio.yml vendored Normal file
View File

@@ -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.

View File

@@ -16,7 +16,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.

View File

@@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Run golangci-lint
uses: reviewdog/action-golangci-lint@v2
with:

View File

@@ -26,7 +26,7 @@ jobs:
GO111MODULE: on
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:
@@ -72,6 +72,10 @@ jobs:
working-directory: ./memory
run: gosec ./...
# -----
- name: Run Gosec (minio)
working-directory: ./minio
run: gosec ./...
# -----
- name: Run Gosec (mongodb)
working-directory: ./mongodb
run: gosec ./...

View File

@@ -26,7 +26,7 @@ jobs:
GO111MODULE: on
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:

View File

@@ -0,0 +1,19 @@
name: Release Drafter Memory
on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master
- main
paths:
- 'memory/**'
jobs:
draft_release_memcache:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter-memory.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -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 }}

View File

@@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 2

View File

@@ -27,7 +27,7 @@ jobs:
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:

View File

@@ -23,7 +23,7 @@ jobs:
run: |
docker run -d -p 10000:10000 mcr.microsoft.com/azure-storage/azurite azurite-blob --blobHost 0.0.0.0 --blobPort 10000
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:

View File

@@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:

View File

@@ -20,7 +20,7 @@ jobs:
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:

View File

@@ -20,7 +20,7 @@ jobs:
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Startup Coherence
run: |
docker run -d -p 1408:1408 -p 30000:30000 ghcr.io/oracle/coherence-ce:22.06.5

View File

@@ -20,7 +20,7 @@ jobs:
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install couchbase
run: |
docker run --name couchbase -d -p 8091-8097:8091-8097 -p 9123:9123 -p 11207:11207 -p 11210:11210 -p 11280:11280 -p 18091-18097:18091-18097 couchbase:enterprise-7.1.1

View File

@@ -25,7 +25,7 @@ jobs:
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:

View File

@@ -20,7 +20,7 @@ jobs:
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install etcd
run: |
docker run -d --name Etcd-server \

View File

@@ -25,7 +25,7 @@ jobs:
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:

View File

@@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:

33
.github/workflows/test-minio.yml vendored Normal file
View File

@@ -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@v4
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '${{ matrix.go-version }}'
- name: Run Test
run: cd ./minio && go test ./... -v -race

View File

@@ -25,7 +25,7 @@ jobs:
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:

View File

@@ -37,7 +37,7 @@ jobs:
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:

View File

@@ -33,7 +33,7 @@ jobs:
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:

View File

@@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:

View File

@@ -32,7 +32,7 @@ jobs:
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:

View File

@@ -23,7 +23,7 @@ jobs:
- '7.x'
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Redis
uses: shogo82148/actions-setup-redis@v1

View File

@@ -20,7 +20,7 @@ jobs:
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:

View File

@@ -22,7 +22,7 @@ jobs:
- '7.x'
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Generate TLS certs
run: ./.github/scripts/gen-test-certs.sh

View File

@@ -20,16 +20,9 @@ jobs:
- 1.21.x
steps:
- name: Install MinIO
run: |
docker run -d -p 9000:9000 --name minio minio/minio server /data
export AWS_ACCESS_KEY_ID=minioadmin
export AWS_SECRET_ACCESS_KEY=minioadmin
export AWS_EC2_METADATA_DISABLED=true
aws --endpoint-url http://127.0.0.1:9000/ s3 mb s3://testbucket
run: docker run -d -p 9000:9000 --name minio minio/minio server /data
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:

View File

@@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:

View File

@@ -60,6 +60,7 @@ type Storage interface {
- [Etcd](./etcd/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Etcd%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-etcd.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
- [Memcache](./memcache/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Memcache%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-memcache.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
- [Memory](./memory/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Local+Storage%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-memory.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
- [Minio](./minio/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Minio%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-minio.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
- [MongoDB](./mongodb/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Mongodb%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-mongodb.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
- [MSSQL](./mssql/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+MSSQL%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-mssql.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
- [MySQL](./mysql/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+MySQL%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-mysql.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>

View File

@@ -4,8 +4,8 @@ go 1.19
require (
github.com/aws/aws-sdk-go-v2 v1.21.0
github.com/aws/aws-sdk-go-v2/config v1.18.36
github.com/aws/aws-sdk-go-v2/credentials v1.13.35
github.com/aws/aws-sdk-go-v2/config v1.18.38
github.com/aws/aws-sdk-go-v2/credentials v1.13.36
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.39
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.21.5
github.com/stretchr/testify v1.8.4
@@ -20,7 +20,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.14 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.35 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.35 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.13.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.13.6 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.21.5 // indirect
github.com/aws/smithy-go v1.14.2 // indirect

View File

@@ -1,9 +1,9 @@
github.com/aws/aws-sdk-go-v2 v1.21.0 h1:gMT0IW+03wtYJhRqTVYn0wLzwdnK9sRMcxmtfGzRdJc=
github.com/aws/aws-sdk-go-v2 v1.21.0/go.mod h1:/RfNgGmRxI+iFOB1OeJUyxiU+9s88k3pfHvDagGEp0M=
github.com/aws/aws-sdk-go-v2/config v1.18.36 h1:mLNA12PWU1Y+ueOO79QgQfKIPhc1MYKl44RmvASkJ7Q=
github.com/aws/aws-sdk-go-v2/config v1.18.36/go.mod h1:8AnEFxW9/XGKCbjYDCJy7iltVNyEI9Iu9qC21UzhhgQ=
github.com/aws/aws-sdk-go-v2/credentials v1.13.35 h1:QpsNitYJu0GgvMBLUIYu9H4yryA5kMksjeIVQfgXrt8=
github.com/aws/aws-sdk-go-v2/credentials v1.13.35/go.mod h1:o7rCaLtvK0hUggAGclf76mNGGkaG5a9KWlp+d9IpcV8=
github.com/aws/aws-sdk-go-v2/config v1.18.38 h1:CByQCELMgm2tM1lAehx3XNg0R/pfeXsYzqn0Aq2chJQ=
github.com/aws/aws-sdk-go-v2/config v1.18.38/go.mod h1:vNm9Hf5VgG2fSUWhT3zFrqN/RosGcabFMYgiSoxKFU8=
github.com/aws/aws-sdk-go-v2/credentials v1.13.36 h1:ps0cPswZjpsOk6sLwG6fdXTzrYjCplgPEyG3OUbbdqE=
github.com/aws/aws-sdk-go-v2/credentials v1.13.36/go.mod h1:sY2phUzxbygoyDtTXhqi7GjGjCQ1S5a5Rj8u3ksBxCg=
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.39 h1:DX/r3aNL7pIVn0K5a+ESL0Fw9ti7Rj05pblEiIJtPmQ=
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.39/go.mod h1:oTk09orqXlwSKnKf+UQhy+4Ci7aCo9x8hn0ZvPCLrns=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.11 h1:uDZJF1hu0EVT/4bogChk8DyjSF6fof6uL/0Y26Ma7Fg=
@@ -24,8 +24,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.35 h1:UKjp
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.35/go.mod h1:B3dUg0V6eJesUTi+m27NUkj7n8hdDKYUpxj8f4+TqaQ=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.35 h1:CdzPW9kKitgIiLV1+MHobfR5Xg25iYnyzWZhyQuSlDI=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.35/go.mod h1:QGF2Rs33W5MaN9gYdEQOBBFPLwTZkEhRwI33f7KIG0o=
github.com/aws/aws-sdk-go-v2/service/sso v1.13.5 h1:oCvTFSDi67AX0pOX3PuPdGFewvLRU2zzFSrTsgURNo0=
github.com/aws/aws-sdk-go-v2/service/sso v1.13.5/go.mod h1:fIAwKQKBFu90pBxx07BFOMJLpRUGu8VOzLJakeY+0K4=
github.com/aws/aws-sdk-go-v2/service/sso v1.13.6 h1:2PylFCfKCEDv6PeSN09pC/VUiRd10wi1VfHG5FrW0/g=
github.com/aws/aws-sdk-go-v2/service/sso v1.13.6/go.mod h1:fIAwKQKBFu90pBxx07BFOMJLpRUGu8VOzLJakeY+0K4=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.5 h1:dnInJb4S0oy8aQuri1mV6ipLlnZPfnsDNB9BGO9PDNY=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.5/go.mod h1:yygr8ACQRY2PrEcy3xsUI357stq2AxnFM6DIsR9lij4=
github.com/aws/aws-sdk-go-v2/service/sts v1.21.5 h1:CQBFElb0LS8RojMJlxRSo/HXipvTZW2S44Lt9Mk2aYQ=

126
minio/README.md Normal file
View File

@@ -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
}
```

88
minio/config.go Normal file
View File

@@ -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
}

31
minio/go.mod Normal file
View File

@@ -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
)

56
minio/go.sum Normal file
View File

@@ -0,0 +1,56 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
github.com/minio/minio-go/v7 v7.0.63 h1:GbZ2oCvaUdgT5640WJOpyDhhDxvknAJU2/T3yurwcbQ=
github.com/minio/minio-go/v7 v7.0.63/go.mod h1:Q6X7Qjb7WMhvG65qKf4gUgA5XaiSox74kR1uAEjxRS4=
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

171
minio/minio.go Normal file
View File

@@ -0,0 +1,171 @@
package minio
import (
"bytes"
"context"
"errors"
"log"
"net/http"
"time"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/valyala/bytebufferpool"
)
// Storage interface that is implemented by storage providers
type Storage struct {
minio *minio.Client
cfg Config
ctx context.Context
}
// New creates a new storage
func New(config ...Config) *Storage {
// Set default config
cfg := configDefault(config...)
// Minio instance
minioClient, err := minio.New(cfg.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(cfg.Credentials.AccessKeyID, cfg.Credentials.SecretAccessKey, cfg.Token),
Secure: cfg.Secure,
Region: cfg.Region,
})
if err != nil {
panic(err)
}
storage := &Storage{minio: minioClient, cfg: cfg, ctx: context.Background()}
// Reset all entries if set to true
if cfg.Reset {
if err = storage.Reset(); err != nil {
panic(err)
}
}
// check bucket
err = storage.CheckBucket()
if err != nil {
// create bucket
err = storage.CreateBucket()
if err != nil {
panic(err)
}
}
return storage
}
// Get value by key
func (s *Storage) Get(key string) ([]byte, error) {
if len(key) <= 0 {
return nil, errors.New("the key value is required")
}
// get object
object, err := s.minio.GetObject(s.ctx, s.cfg.Bucket, key, s.cfg.GetObjectOptions)
if err != nil {
return nil, err
}
// convert to byte
bb := bytebufferpool.Get()
defer bytebufferpool.Put(bb)
_, err = bb.ReadFrom(object)
if err != nil {
return nil, err
}
return bb.Bytes(), nil
}
// Set key with value
func (s *Storage) Set(key string, val []byte, exp time.Duration) error {
if len(key) <= 0 {
return errors.New("the key value is required")
}
// create Reader
file := bytes.NewReader(val)
// set content type
s.cfg.PutObjectOptions.ContentType = http.DetectContentType(val)
// put object
_, err := s.minio.PutObject(s.ctx, s.cfg.Bucket, key, file, file.Size(), s.cfg.PutObjectOptions)
return err
}
// Delete entry by key
func (s *Storage) Delete(key string) error {
if len(key) <= 0 {
return errors.New("the key value is required")
}
// remove
err := s.minio.RemoveObject(s.ctx, s.cfg.Bucket, key, s.cfg.RemoveObjectOptions)
return err
}
// Reset all entries, including unexpired
func (s *Storage) Reset() error {
objectsCh := make(chan minio.ObjectInfo)
// Send object names that are needed to be removed to objectsCh
go func() {
defer close(objectsCh)
// List all objects from a bucket-name with a matching prefix.
for object := range s.minio.ListObjects(s.ctx, s.cfg.Bucket, s.cfg.ListObjectsOptions) {
if object.Err != nil {
log.Println(object.Err)
}
objectsCh <- object
}
}()
opts := minio.RemoveObjectsOptions{
GovernanceBypass: true,
}
for err := range s.minio.RemoveObjects(s.ctx, s.cfg.Bucket, objectsCh, opts) {
log.Println("Error detected during deletion: ", err)
}
return nil
}
// Close the storage
func (s *Storage) Close() error {
return nil
}
// CheckBucket Check to see if bucket already exists
func (s *Storage) CheckBucket() error {
exists, err := s.minio.BucketExists(s.ctx, s.cfg.Bucket)
if !exists || err != nil {
return errors.New("the specified bucket does not exist")
}
return nil
}
// CreateBucket Bucket not found so Make a new bucket
func (s *Storage) CreateBucket() error {
return s.minio.MakeBucket(s.ctx, s.cfg.Bucket, minio.MakeBucketOptions{Region: s.cfg.Region})
}
// RemoveBucket Bucket remove if bucket is empty
func (s *Storage) RemoveBucket() error {
return s.minio.RemoveBucket(s.ctx, s.cfg.Bucket)
}
// Conn Return minio client
func (s *Storage) Conn() *minio.Client {
return s.minio
}

184
minio/minio_test.go Normal file
View File

@@ -0,0 +1,184 @@
package minio
import (
"strconv"
"testing"
"time"
"github.com/stretchr/testify/require"
)
var testStore = New(
Config{
Bucket: "fiber-bucket",
Endpoint: "localhost:9000",
Credentials: Credentials{
AccessKeyID: "minio-user",
SecretAccessKey: "minio-password",
},
},
)
func Test_Get(t *testing.T) {
var (
key = "john"
val = []byte("doe")
)
err := testStore.Set(key, val, 0)
require.NoError(t, err)
result, err := testStore.Get(key)
require.NoError(t, err)
require.Equal(t, val, result)
result, err = testStore.Get("doe")
require.Error(t, err)
require.Zero(t, len(result))
}
func Test_Get_Empty_Key(t *testing.T) {
var (
key = ""
)
_, err := testStore.Get(key)
require.Error(t, err)
require.EqualError(t, err, "the key value is required")
}
func Test_Get_Not_Exists_Key(t *testing.T) {
var (
key = "not-exists"
)
_, err := testStore.Get(key)
require.Error(t, err)
require.EqualError(t, err, "The specified key does not exist.")
}
func Test_Get_Not_Exists_Bucket(t *testing.T) {
var (
key = "john"
)
// random bucket name
testStore.cfg.Bucket = strconv.FormatInt(time.Now().UnixMicro(), 10)
result, err := testStore.Get(key)
require.Error(t, err)
require.Zero(t, len(result))
require.EqualError(t, err, "The specified bucket does not exist")
testStore.cfg.Bucket = "fiber-bucket"
}
func Test_Set(t *testing.T) {
var (
key = "john"
val = []byte("doe")
)
err := testStore.Set(key, val, 0)
require.NoError(t, err)
}
func Test_Set_Empty_Key(t *testing.T) {
var (
key = ""
val = []byte("doe")
)
err := testStore.Set(key, val, 0)
require.Error(t, err)
require.EqualError(t, err, "the key value is required")
}
func Test_Set_Not_Exists_Bucket(t *testing.T) {
var (
key = "john"
val = []byte("doe")
)
// random bucket name
testStore.cfg.Bucket = strconv.FormatInt(time.Now().UnixMicro(), 10)
err := testStore.Set(key, val, 0)
require.Error(t, err)
require.EqualError(t, err, "The specified bucket does not exist")
testStore.cfg.Bucket = "fiber-bucket"
}
func Test_Delete(t *testing.T) {
var (
key = "john"
val = []byte("doe")
)
err := testStore.Set(key, val, 0)
require.NoError(t, err)
err = testStore.Delete(key)
require.NoError(t, err)
}
func Test_Delete_Empty_Key(t *testing.T) {
var (
key = ""
val = []byte("doe")
)
err := testStore.Set(key, val, 0)
require.Error(t, err)
require.EqualError(t, err, "the key value is required")
}
func Test_Delete_Not_Exists_Bucket(t *testing.T) {
var (
key = "john"
)
// random bucket name
testStore.cfg.Bucket = strconv.FormatInt(time.Now().UnixMicro(), 10)
err := testStore.Delete(key)
require.Error(t, err)
require.EqualError(t, err, "The specified bucket does not exist")
testStore.cfg.Bucket = "fiber-bucket"
}
func Test_Reset(t *testing.T) {
var (
val = []byte("doe")
)
err := testStore.Set("john1", val, 0)
require.NoError(t, err)
err = testStore.Set("john2", val, 0)
require.NoError(t, err)
err = testStore.Reset()
require.NoError(t, err)
result, err := testStore.Get("john1")
require.Error(t, err)
require.Zero(t, len(result))
}
func Test_Close(t *testing.T) {
require.NoError(t, testStore.Close())
}

View File

@@ -3,7 +3,7 @@ module github.com/gofiber/storage/mssql/v2
go 1.19
require (
github.com/microsoft/go-mssqldb v1.5.0
github.com/microsoft/go-mssqldb v1.6.0
github.com/stretchr/testify v1.8.4
)
@@ -13,5 +13,6 @@ require (
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/text v0.12.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View File

@@ -1,99 +1,32 @@
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0/go.mod h1:OQeznEEkTZ9OrhHJoDD8ZDq51FHgXjqtP9z6bEwBq9U=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM=
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.1 h1:/iHxaJhsFr0+xVFfbMr5vxz848jyiWuIEDhYq3y5odY=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 h1:vcYCAze6p19qBW7MhZybIsqD8sMV8js0NyQM8JDnVtg=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY=
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.0 h1:yfJe15aSwEQ6Oo6J+gdfdulPNoZ3TEhmbhLIoxZcA+U=
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v0.8.0 h1:T028gtTPiYt/RMUfs8nVsAL7FDQrfLlrm/NnRG/zcC4=
github.com/AzureAD/microsoft-authentication-library-for-go v1.1.0 h1:HCc0+LpPfpCKs6LGGLAhwBARt9632unrVcI6i8s/8os=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM=
github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo=
github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg=
github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs=
github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/microsoft/go-mssqldb v1.5.0 h1:CgENxkwtOBNj3Jg6T1X209y2blCfTTcwuOlznd2k9fk=
github.com/microsoft/go-mssqldb v1.5.0/go.mod h1:lmWsjHD8XX/Txr0f8ZqgbEZSC+BZjmEQy/Ms+rLrvho=
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/microsoft/go-mssqldb v1.6.0 h1:mM3gYdVwEPFrlg/Dvr2DNVEgYFG7L42l+dGc67NNNpc=
github.com/microsoft/go-mssqldb v1.6.0/go.mod h1:00mDtPbeQCRGC1HwOOR5K/gr30P1NcEG0vx6Kbv2aJU=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -4,7 +4,7 @@ go 1.20
require (
github.com/gofiber/utils/v2 v2.0.0-beta.3
github.com/redis/rueidis v1.0.16
github.com/redis/rueidis v1.0.17
github.com/stretchr/testify v1.8.4
)

View File

@@ -10,8 +10,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/rueidis v1.0.16 h1:ieB3AqZe9GcuTWZL8PFu1Mfn+pfqjBZAJEZh7zOcwSI=
github.com/redis/rueidis v1.0.16/go.mod h1:8B+r5wdnjwK3lTFml5VtxjzGOQAC+5UmujoD12pDrEo=
github.com/redis/rueidis v1.0.17 h1:RyjiBVnPcKxjgiUpkyqbRw/OFJV5vX2bMM/oMPdz8JE=
github.com/redis/rueidis v1.0.17/go.mod h1:8B+r5wdnjwK3lTFml5VtxjzGOQAC+5UmujoD12pDrEo=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=

View File

@@ -31,8 +31,15 @@ func (s *Storage) Delete(key string) error
func (s *Storage) Reset() error
func (s *Storage) Close() error
func (s *Storage) Conn() *s3.Client
// Additional useful methods.
func (s *Storage) CreateBucker(bucket string) error
func (s *Storage) DeleteBucket(bucket string) error
func (s *Storage) SetWithChecksum(key string, val []byte, checksum map[types.ChecksumAlgorithm][]byte) error
```
### Installation
S3 is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet:
```bash
go mod init github.com/<user>/<repo>
@@ -43,7 +50,9 @@ go get github.com/gofiber/storage/s3/v2
```
### Examples
Import the storage package.
```go
import "github.com/gofiber/storage/s3/v2"
```
@@ -62,6 +71,38 @@ store := s3.New(s3.Config{
})
```
Create an object with `Set()`:
```go
err := store.Set("my-key", []byte("my-value"))
```
Or, call `SetWithChecksum()` to create an object with checksum to
ask S3 server to verify data integrity on server side:
> Currently 4 algorithms are supported:
> - types.ChecksumAlgorithmCrc32 (`CRC32`)
> - types.ChecksumAlgorithmCrc32c (`CRC32C`)
> - types.ChecksumAlgorithmSha1 (`SHA1`)
> - types.ChecksumAlgorithmSha256 (`SHA256`)
>
> For more information, see [PutObjectInput](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/s3#PutObjectInput).
```go
key := "my-key"
val := []byte("my-value")
hash := sha256.New()
hash.Write(val)
sha256sum := hash.Sum(nil)
// import "github.com/aws/aws-sdk-go-v2/service/s3/types"
checksum = map[types.ChecksumAlgorithm][]byte{
types.ChecksumAlgorithmSha256: sha256sum,
}
err := store.SetWithChecksum(key, val, checksum)
```
### Config
```go
// Config defines the config for storage.
@@ -104,7 +145,9 @@ type Credentials struct {
```
### 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{

View File

@@ -4,9 +4,9 @@ go 1.19
require (
github.com/aws/aws-sdk-go-v2 v1.21.0
github.com/aws/aws-sdk-go-v2/config v1.18.36
github.com/aws/aws-sdk-go-v2/credentials v1.13.35
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.80
github.com/aws/aws-sdk-go-v2/config v1.18.38
github.com/aws/aws-sdk-go-v2/credentials v1.13.36
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.82
github.com/aws/aws-sdk-go-v2/service/s3 v1.38.5
github.com/stretchr/testify v1.8.4
)
@@ -22,7 +22,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.36 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.35 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.13.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.13.6 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.21.5 // indirect
github.com/aws/smithy-go v1.14.2 // indirect

View File

@@ -2,14 +2,14 @@ github.com/aws/aws-sdk-go-v2 v1.21.0 h1:gMT0IW+03wtYJhRqTVYn0wLzwdnK9sRMcxmtfGzR
github.com/aws/aws-sdk-go-v2 v1.21.0/go.mod h1:/RfNgGmRxI+iFOB1OeJUyxiU+9s88k3pfHvDagGEp0M=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.13 h1:OPLEkmhXf6xFPiz0bLeDArZIDx1NNS4oJyG4nv3Gct0=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.13/go.mod h1:gpAbvyDGQFozTEmlTFO8XcQKHzubdq0LzRyJpG6MiXM=
github.com/aws/aws-sdk-go-v2/config v1.18.36 h1:mLNA12PWU1Y+ueOO79QgQfKIPhc1MYKl44RmvASkJ7Q=
github.com/aws/aws-sdk-go-v2/config v1.18.36/go.mod h1:8AnEFxW9/XGKCbjYDCJy7iltVNyEI9Iu9qC21UzhhgQ=
github.com/aws/aws-sdk-go-v2/credentials v1.13.35 h1:QpsNitYJu0GgvMBLUIYu9H4yryA5kMksjeIVQfgXrt8=
github.com/aws/aws-sdk-go-v2/credentials v1.13.35/go.mod h1:o7rCaLtvK0hUggAGclf76mNGGkaG5a9KWlp+d9IpcV8=
github.com/aws/aws-sdk-go-v2/config v1.18.38 h1:CByQCELMgm2tM1lAehx3XNg0R/pfeXsYzqn0Aq2chJQ=
github.com/aws/aws-sdk-go-v2/config v1.18.38/go.mod h1:vNm9Hf5VgG2fSUWhT3zFrqN/RosGcabFMYgiSoxKFU8=
github.com/aws/aws-sdk-go-v2/credentials v1.13.36 h1:ps0cPswZjpsOk6sLwG6fdXTzrYjCplgPEyG3OUbbdqE=
github.com/aws/aws-sdk-go-v2/credentials v1.13.36/go.mod h1:sY2phUzxbygoyDtTXhqi7GjGjCQ1S5a5Rj8u3ksBxCg=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.11 h1:uDZJF1hu0EVT/4bogChk8DyjSF6fof6uL/0Y26Ma7Fg=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.11/go.mod h1:TEPP4tENqBGO99KwVpV9MlOX4NSrSLP8u3KRy2CDwA8=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.80 h1:UrlTIXE+X+u/680ZIPkuM5QYg1D5+bWjlOGlOfHCptU=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.80/go.mod h1:57ALQch4qLc5kVWTHloB61HfmMc8ZlAgia3xEO2Bolc=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.82 h1:gPh2fLhr1kwH2HXFhs1kCblIgHTabqE1N9gwYPhS/fw=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.82/go.mod h1:4pzmxw8ZmkpbvGqrmedWaXuDL2xcABews1VLYqe9Djk=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41 h1:22dGT7PneFMx4+b3pz7lMTRyN8ZKH7M2cW4GP9yUS2g=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41/go.mod h1:CrObHAuPneJBlfEJ5T3szXOUkLEThaGfvnhTf33buas=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35 h1:SijA0mgjV8E+8G45ltVHs0fvKpTj8xmZJ3VwhGKtUSI=
@@ -28,8 +28,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.4 h1:v0jkRigbSD6uOd
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.4/go.mod h1:LhTyt8J04LL+9cIt7pYJ5lbS/U98ZmXovLOR/4LUsk8=
github.com/aws/aws-sdk-go-v2/service/s3 v1.38.5 h1:A42xdtStObqy7NGvzZKpnyNXvoOmm+FENobZ0/ssHWk=
github.com/aws/aws-sdk-go-v2/service/s3 v1.38.5/go.mod h1:rDGMZA7f4pbmTtPOk5v5UM2lmX6UAbRnMDJeDvnH7AM=
github.com/aws/aws-sdk-go-v2/service/sso v1.13.5 h1:oCvTFSDi67AX0pOX3PuPdGFewvLRU2zzFSrTsgURNo0=
github.com/aws/aws-sdk-go-v2/service/sso v1.13.5/go.mod h1:fIAwKQKBFu90pBxx07BFOMJLpRUGu8VOzLJakeY+0K4=
github.com/aws/aws-sdk-go-v2/service/sso v1.13.6 h1:2PylFCfKCEDv6PeSN09pC/VUiRd10wi1VfHG5FrW0/g=
github.com/aws/aws-sdk-go-v2/service/sso v1.13.6/go.mod h1:fIAwKQKBFu90pBxx07BFOMJLpRUGu8VOzLJakeY+0K4=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.5 h1:dnInJb4S0oy8aQuri1mV6ipLlnZPfnsDNB9BGO9PDNY=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.15.5/go.mod h1:yygr8ACQRY2PrEcy3xsUI357stq2AxnFM6DIsR9lij4=
github.com/aws/aws-sdk-go-v2/service/sts v1.21.5 h1:CQBFElb0LS8RojMJlxRSo/HXipvTZW2S44Lt9Mk2aYQ=

38
s3/init_test.go Normal file
View File

@@ -0,0 +1,38 @@
package s3
import (
"os"
"testing"
"time"
)
const (
bucket = "testbucket"
)
var testStore *Storage
func TestMain(m *testing.M) {
testStore = New(
Config{
Bucket: bucket,
Endpoint: "http://127.0.0.1:9000/",
Region: "us-east-1",
Credentials: Credentials{
AccessKey: "minioadmin",
SecretAccessKey: "minioadmin",
},
RequestTimeout: 3 * time.Second,
},
)
// Create test bucket.
_ = testStore.CreateBucket(bucket)
exitVal := m.Run()
// Delete test bucket.
_ = testStore.DeleteBucket(bucket)
os.Exit(exitVal)
}

View File

@@ -159,7 +159,7 @@ func (s *Storage) Close() error {
return nil
}
// Return database client
// Conn returns database client.
func (s *Storage) Conn() *s3.Client {
return s.svc
}
@@ -186,11 +186,11 @@ func returnAWSConfig(cfg Config) (aws.Config, error) {
})
if cfg.Credentials != (Credentials{}) {
credentials := credentials.NewStaticCredentialsProvider(cfg.Credentials.AccessKey, cfg.Credentials.SecretAccessKey, "")
creds := credentials.NewStaticCredentialsProvider(cfg.Credentials.AccessKey, cfg.Credentials.SecretAccessKey, "")
return awsconfig.LoadDefaultConfig(context.TODO(),
awsconfig.WithRegion(cfg.Region),
awsconfig.WithEndpointResolverWithOptions(endpoint),
awsconfig.WithCredentialsProvider(credentials),
awsconfig.WithCredentialsProvider(creds),
awsconfig.WithRetryer(func() aws.Retryer {
return retry.AddWithMaxAttempts(retry.NewStandard(), cfg.MaxAttempts)
}),

83
s3/s3_methods.go Normal file
View File

@@ -0,0 +1,83 @@
package s3
import (
"bytes"
"encoding/base64"
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
)
// Additional methods for S3, but not required by gofiber Storage interface.
// CreateBucket creates a new bucket.
func (s *Storage) CreateBucket(bucket string) error {
ctx, cancel := s.requestContext()
defer cancel()
_, err := s.svc.CreateBucket(ctx, &s3.CreateBucketInput{
Bucket: aws.String(bucket),
})
return err
}
// DeleteBucket deletes a bucket.
func (s *Storage) DeleteBucket(bucket string) error {
ctx, cancel := s.requestContext()
defer cancel()
_, err := s.svc.DeleteBucket(ctx, &s3.DeleteBucketInput{
Bucket: aws.String(bucket),
})
return err
}
// SetWithChecksum sets key with value and checksum.
//
// Currently 4 algorithms are supported:
// - types.ChecksumAlgorithmCrc32 (`CRC32`)
// - types.ChecksumAlgorithmCrc32c (`CRC32C`)
// - types.ChecksumAlgorithmSha1 (`SHA1`)
// - types.ChecksumAlgorithmSha256 (`SHA256`)
//
// For more information, see [PutObjectInput](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/s3#PutObjectInput).
func (s *Storage) SetWithChecksum(key string, val []byte, checksum map[types.ChecksumAlgorithm][]byte) error {
if len(key) <= 0 {
return nil
}
poi := s3.PutObjectInput{
Bucket: &s.bucket,
Key: aws.String(key),
Body: bytes.NewReader(val),
}
for alg, sum := range checksum {
// S3 requires base64 encoded checksum.
b64str := base64.StdEncoding.EncodeToString(sum)
switch alg {
case types.ChecksumAlgorithmCrc32:
poi.ChecksumCRC32 = aws.String(b64str)
case types.ChecksumAlgorithmCrc32c:
poi.ChecksumCRC32C = aws.String(b64str)
case types.ChecksumAlgorithmSha1:
poi.ChecksumSHA1 = aws.String(b64str)
case types.ChecksumAlgorithmSha256:
poi.ChecksumSHA256 = aws.String(b64str)
default:
return fmt.Errorf("invalid checksum algorithm: %s", alg)
}
}
ctx, cancel := s.requestContext()
defer cancel()
_, err := s.uploader.Upload(ctx, &poi)
return err
}

50
s3/s3_methods_test.go Normal file
View File

@@ -0,0 +1,50 @@
package s3
import (
"crypto/sha256"
"testing"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/stretchr/testify/require"
)
func Test_S3_CreateDeleteBucket(t *testing.T) {
bkt := "test-new-bucket"
err := testStore.CreateBucket(bkt)
require.NoError(t, err)
err = testStore.DeleteBucket(bkt)
require.NoError(t, err)
}
func Test_S3_SetWithChecksum(t *testing.T) {
var (
key = "set-with-checksum"
val = []byte("doe")
)
// Create SHA-256 hash and get checksum.
sha256Hash := sha256.New()
sha256Hash.Write(val)
sha256sum := sha256Hash.Sum(nil)
checksum := map[types.ChecksumAlgorithm][]byte{
types.ChecksumAlgorithmSha256: sha256sum,
}
err := testStore.SetWithChecksum(key, val, checksum)
require.NoError(t, err)
result, err := testStore.Get(key)
require.NoError(t, err)
// Compare value.
require.Equal(t, result, val)
// Compare checksum.
hash2 := sha256.New()
hash2.Write(result)
sha256sum2 := hash2.Sum(nil)
require.Equal(t, sha256sum, sha256sum2)
}

View File

@@ -6,18 +6,6 @@ import (
"github.com/stretchr/testify/require"
)
var testStore = New(
Config{
Bucket: "testbucket",
Endpoint: "http://127.0.0.1:9000/",
Region: "us-east-1",
Credentials: Credentials{
AccessKey: "minioadmin",
SecretAccessKey: "minioadmin",
},
},
)
func Test_S3_Set(t *testing.T) {
var (
key = "john"