写操作:
func MinioWrite(num int){
client, err := minio.New(
"127.0.0.1:9001",
&minio.Options{
Creds: credentials.NewStaticV4("minio", "minio123", ""),
Secure: false,
},
)
if err != nil {
panic(err)
}
f, err := os.Open("ability.jpg")
if err != nil {
panic(err)
}
defer f.Close()
if _, err := client.PutObject(
context.Background(),
"image",
fmt.Sprintf("test%v.jpg",num),
f,
-1,
minio.PutObjectOptions{ContentType: "image/jpeg"},
); err != nil {
panic(err)
}
}
删除操作:
func MinioRemove(num int){
client, err := minio.New(
"127.0.0.1:9001",
&minio.Options{
Creds: credentials.NewStaticV4("minio", "minio123", ""),
Secure: false,
},
)
if err != nil {
panic(err)
}
if err := client.RemoveObject(
context.Background(),
"image",
fmt.Sprintf("test%v.jpg",num),
minio.RemoveObjectOptions{},
); err != nil {
panic(err)
}
}
下载操作
func MinioGet(num int){
client, err := minio.New(
"127.0.0.1:9001",
&minio.Options{
Creds: credentials.NewStaticV4("minio", "minio123", ""),
Secure: false,
},
)
if err != nil {
panic(err)
}
ff,err := client.GetObject(
context.Background(),
"image",
fmt.Sprintf("test%v.jpg",num),
minio.GetObjectOptions{},
)
if err != nil {
panic(err)
}
file3, error := os.Create(fmt.Sprintf("./test%v.jpg",num))
if error != nil {
fmt.Println(error)
}
text,_:=ioutil.ReadAll(ff)
file3.Write(text)
defer file3.Close()
wg.Done()
}