gominio

package
v1.2.65 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

go.minio

基于 github.com/minio/minio-go/v7 封装

package main

import (
	"context"
	"flag"
	"fmt"
	gominio "github.com/gif-gif/go.io/go-minio"
	"github.com/minio/minio-go/v7"
	"net/url"
	"os"
	"strings"
	"time"
)

var (
	AccessKeyId     = flag.String("access_key_id", "fPztco0yxWC1qrxz6iDN", "")
	AccessKeySecret = flag.String("access_key_secret", "kWS6q1PIxjcEnLSkoBWrWqPnsHFHm1Q8cvG1CUPm", "")
	Endpoint        = flag.String("endpoint", "minio.gif00.com", "")
	Bucket          = flag.String("bucket", "test", "")
	Domain          = flag.String("domain", "", "")
)

func createBucketTest() {
	conf := gominio.Config{
		AccessKeyId:     *AccessKeyId,
		AccessKeySecret: *AccessKeySecret,
		Endpoint:        *Endpoint,
		Bucket:          *Bucket,
		Domain:          *Domain,
		UseSSL:          false,
	}

	oss := gominio.New(conf)
	bucketName := "testbucket"
	location := "us-east-1"

	err := oss.CreateBucket(context.Background(), bucketName, location)
	if err != nil {
		fmt.Println(err.Error())
	} else {
		fmt.Println("Created bucket successfully")
	}

}

func uploadTest() {
	args := os.Args
	if l := len(args); l < 2 {
		fmt.Println("请选择上传文件!")
		return
	}

	conf := gominio.Config{
		AccessKeyId:     *AccessKeyId,
		AccessKeySecret: *AccessKeySecret,
		Endpoint:        *Endpoint,
		Bucket:          *Bucket,
		Domain:          *Domain,
		UseSSL:          false,
	}

	oss := gominio.New(conf)

	for n, i := range args {
		if n == 0 {
			continue
		}

		var filename string
		index := strings.LastIndex(i, "/")
		if index == -1 {
			filename = i
		} else {
			filename = i[index+1:]
		}

		info, err := oss.FPutObject(context.Background(), strings.ToLower(filename), i, &minio.PutObjectOptions{
			Expires: time.Now().AddDate(0, 0, 1),
		})
		if err != nil {
			fmt.Println(err.Error())
			continue
		}
		fmt.Println(info)
	}
}

func getTest() {

	conf := gominio.Config{
		AccessKeyId:     *AccessKeyId,
		AccessKeySecret: *AccessKeySecret,
		Endpoint:        *Endpoint,
		Bucket:          *Bucket,
		Domain:          *Domain,
		UseSSL:          false,
	}

	oss := gominio.New(conf)

	err := oss.FGetObject(context.Background(), "/test/2024/05/422744271b108960a4818cc91a1822d9.log", "/Users/Jerry/Desktop/bak202405/422744271b108960a4818cc91a1822d9.log", nil)
	if err != nil {
		fmt.Println(err.Error())
	} else {
		fmt.Println("get object succeeded")
	}

	for object := range oss.ListObjects("test", nil) {
		if object.Err != nil {
			fmt.Println(object.Err)
			return
		}
		fmt.Println("found:", object)
	}

	// Set request parameters for content-disposition.
	reqParams := make(url.Values)
	reqParams.Set("response-content-disposition", "attachment; filename=\"your-filename.txt\"")

	// Generates a presigned url which expires in a day.
	presignedURL, err := oss.PresignedGetObject("test", "test.apk", time.Second*24*60*60, reqParams)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("Successfully generated presigned URL", presignedURL)
}

func main() {
	//uploadTest()
	//createBucketTest()
	getTest()
}


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init added in v1.2.39

func Init(configs ...Config) (err error)

Types

type Config

type Config struct {
	Name            string `json:"name,optional"  yaml:"Name"`
	AccessKeyId     string `json:"accessKeyId,optional"  yaml:"AccessKeyId"`
	AccessKeySecret string `json:"accessKeySecret,optional"  yaml:"AccessKeySecret"`
	Endpoint        string `json:"endpoint,optional"  yaml:"Endpoint"`
	Bucket          string `json:"bucket,optional"  yaml:"Bucket"`
	Dir             string `json:"dir,optional"  yaml:"Dir"`
	Domain          string `json:"domain,optional"  yaml:"Domain,optional"`
	UseSSL          bool   `json:"useSSL,optional"  yaml:"UseSSL"`
	Open            bool   `json:"open,optional"  yaml:"Open"`
}

type Uploader added in v1.2.39

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

func Create added in v1.2.39

func Create(conf Config) (*Uploader, error)

func Default added in v1.2.39

func Default() *Uploader

func GetClient added in v1.2.39

func GetClient(names ...string) *Uploader

func New

func New(conf Config) (*Uploader, error)

func (*Uploader) BucketExists added in v1.2.39

func (o *Uploader) BucketExists(bucketName string) (bool, error)

func (*Uploader) CreateBucket added in v1.2.39

func (o *Uploader) CreateBucket(ctx context.Context, bucketName string, location string) error

func (*Uploader) FGetObject added in v1.2.39

func (o *Uploader) FGetObject(ctx context.Context, objectName, saveFilePath string, options *minio.GetObjectOptions) error

func (*Uploader) FPutObject added in v1.2.39

func (o *Uploader) FPutObject(ctx context.Context, objectName, filePath string, options *minio.PutObjectOptions) (*minio.UploadInfo, error)

func (*Uploader) ListBuckets added in v1.2.39

func (o *Uploader) ListBuckets() ([]minio.BucketInfo, error)

func (*Uploader) ListObjects added in v1.2.39

func (o *Uploader) ListObjects(bucketName string, opts *minio.ListObjectsOptions) <-chan minio.ObjectInfo

func (*Uploader) MinioClient added in v1.2.42

func (g *Uploader) MinioClient() *minio.Client

func (*Uploader) PresignedGetObject added in v1.2.39

func (o *Uploader) PresignedGetObject(bucketName, objectName string, expiry time.Duration, reqParams url.Values) (u *url.URL, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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