forked from gitea/gitea
1
0
Fork 0
gitea/vendor/github.com/minio/minio-go/v7
Lunny Xiao 62e6c9bc6c
Add a storage layer for attachments (#11387)
* Add a storage layer for attachments

* Fix some bug

* fix test

* Fix copyright head and lint

* Fix bug

* Add setting for minio and flags for migrate-storage

* Add documents

* fix lint

* Add test for minio store type on attachments

* fix test

* fix test

* Apply suggestions from code review

Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>

* Add warning when storage migrated successfully

* Fix drone

* fix test

* rebase

* Fix test

* display the error on console

* Move minio test to amd64 since minio docker don't support arm64

* refactor the codes

* add trace

* Fix test

* remove log on xorm

* Fi download bug

* Add a storage layer for attachments

* Add setting for minio and flags for migrate-storage

* fix lint

* Add test for minio store type on attachments

* Apply suggestions from code review

Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>

* Fix drone

* fix test

* Fix test

* display the error on console

* Move minio test to amd64 since minio docker don't support arm64

* refactor the codes

* add trace

* Fix test

* Add URL function to serve attachments directly from S3/Minio

* Add ability to enable/disable redirection in attachment configuration

* Fix typo

* Add a storage layer for attachments

* Add setting for minio and flags for migrate-storage

* fix lint

* Add test for minio store type on attachments

* Apply suggestions from code review

Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>

* Fix drone

* fix test

* Fix test

* display the error on console

* Move minio test to amd64 since minio docker don't support arm64

* don't change unrelated files

* Fix lint

* Fix build

* update go.mod and go.sum

* Use github.com/minio/minio-go/v6

* Remove unused function

* Upgrade minio to v7 and some other improvements

* fix lint

* Fix go mod

Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Co-authored-by: Tyler <tystuyfzand@gmail.com>
2020-08-18 12:23:45 +08:00
..
pkg Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
.gitignore Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
.golangci.yml Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
CNAME Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
CONTRIBUTING.md Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
LICENSE Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
MAINTAINERS.md Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
Makefile Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
NOTICE Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
README.md Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
README_zh_CN.md Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-bucket-encryption.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-bucket-lifecycle.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-bucket-notification.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-bucket-policy.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-bucket-replication.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-bucket-tagging.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-bucket-versioning.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-compose-object.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-datatypes.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-error-response.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-get-object-acl.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-get-object-file.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-get-object.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-get-options.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-list.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-object-legal-hold.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-object-lock.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-object-retention.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-object-tagging.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-presigned.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-put-bucket.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-put-object-common.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-put-object-copy.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-put-object-file-context.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-put-object-multipart.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-put-object-streaming.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-put-object.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-remove.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-s3-datatypes.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-select.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api-stat.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
api.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
bucket-cache.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
code_of_conduct.md Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
constants.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
core.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
go.mod Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
go.sum Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
hook-reader.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
post-policy.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
retry-continous.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
retry.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
s3-endpoints.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
s3-error.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
staticcheck.conf Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
transport.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00
utils.go Add a storage layer for attachments (#11387) 2020-08-18 12:23:45 +08:00

README.md

MinIO Go Client SDK for Amazon S3 Compatible Cloud Storage Slack Sourcegraph Apache V2 License

The MinIO Go Client SDK provides simple APIs to access any Amazon S3 compatible object storage.

This quickstart guide will show you how to install the MinIO client SDK, connect to MinIO, and provide a walkthrough for a simple file uploader. For a complete list of APIs and examples, please take a look at the Go Client API Reference.

This document assumes that you have a working Go development environment.

Download from Github

GO111MODULE=on go get github.com/minio/minio-go/v7

Initialize MinIO Client

MinIO client requires the following four parameters specified to connect to an Amazon S3 compatible object storage.

Parameter Description
endpoint URL to object storage service.
minio.Options All the options such as credentials, custom transport etc.
package main

import (
	"log"

	"github.com/minio/minio-go/v7"
	"github.com/minio/minio-go/v7/pkg/credentials"
)

func main() {
	endpoint := "play.min.io"
	accessKeyID := "Q3AM3UQ867SPQQA43P2F"
	secretAccessKey := "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
	useSSL := true

	// Initialize minio client object.
	minioClient, err := minio.New(endpoint, &minio.Options{
		Creds:  credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
		Secure: useSSL,
	})
	if err != nil {
		log.Fatalln(err)
	}

	log.Printf("%#v\n", minioClient) // minioClient is now setup
}

Quick Start Example - File Uploader

This example program connects to an object storage server, creates a bucket and uploads a file to the bucket.

We will use the MinIO server running at https://play.min.io in this example. Feel free to use this service for testing and development. Access credentials shown in this example are open to the public.

FileUploader.go

package main

import (
	"context"
	"log"

	"github.com/minio/minio-go/v7"
	"github.com/minio/minio-go/v7/pkg/credentials"
)

func main() {
	endpoint := "play.min.io"
	accessKeyID := "Q3AM3UQ867SPQQA43P2F"
	secretAccessKey := "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
	useSSL := true

	// Initialize minio client object.
	minioClient, err := minio.New(endpoint, &minio.Options{
		Creds:  credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
		Secure: useSSL,
	})
	if err != nil {
		log.Fatalln(err)
	}

	// Make a new bucket called mymusic.
	bucketName := "mymusic"
	location := "us-east-1"

	err = minioClient.MakeBucket(context.Background(), bucketName, minio.MakeBucketOptions{Region: location})
	if err != nil {
		// Check to see if we already own this bucket (which happens if you run this twice)
		exists, errBucketExists := minioClient.BucketExists(bucketName)
		if errBucketExists == nil && exists {
			log.Printf("We already own %s\n", bucketName)
		} else {
			log.Fatalln(err)
		}
	} else {
		log.Printf("Successfully created %s\n", bucketName)
	}

	// Upload the zip file
	objectName := "golden-oldies.zip"
	filePath := "/tmp/golden-oldies.zip"
	contentType := "application/zip"

	// Upload the zip file with FPutObject
	n, err := minioClient.FPutObject(context.Background(), bucketName, objectName, filePath, minio.PutObjectOptions{ContentType: contentType})
	if err != nil {
		log.Fatalln(err)
	}

	log.Printf("Successfully uploaded %s of size %d\n", objectName, n)
}

Run FileUploader

go run file-uploader.go
2016/08/13 17:03:28 Successfully created mymusic
2016/08/13 17:03:40 Successfully uploaded golden-oldies.zip of size 16253413

mc ls play/mymusic/
[2016-05-27 16:02:16 PDT]  17MiB golden-oldies.zip

API Reference

The full API Reference is available here.

API Reference : Bucket Operations

API Reference : Bucket policy Operations

API Reference : Bucket notification Operations

API Reference : File Object Operations

API Reference : Object Operations

API Reference : Presigned Operations

API Reference : Client custom settings

Full Examples

Full Examples : Bucket Operations

Full Examples : Bucket policy Operations

Full Examples : Bucket lifecycle Operations

Full Examples : Bucket encryption Operations

Full Examples : Bucket replication Operations

Full Examples : Bucket notification Operations

Full Examples : File Object Operations

Full Examples : Object Operations

Full Examples : Encrypted Object Operations

Full Examples : Presigned Operations

Explore Further

Contribute

Contributors Guide

License

This SDK is distributed under the Apache License, Version 2.0, see LICENSE and NOTICE for more information.