Add rclone.go
This commit is contained in:
parent
af135a7469
commit
480194e1eb
16
go.mod
16
go.mod
|
@ -10,22 +10,12 @@ require (
|
||||||
github.com/casdoor/casdoor-go-sdk v0.9.1
|
github.com/casdoor/casdoor-go-sdk v0.9.1
|
||||||
github.com/danaugrs/go-tsne/tsne v0.0.0-20220306155740-2250969e057f
|
github.com/danaugrs/go-tsne/tsne v0.0.0-20220306155740-2250969e057f
|
||||||
github.com/go-sql-driver/mysql v1.6.0
|
github.com/go-sql-driver/mysql v1.6.0
|
||||||
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
|
github.com/google/uuid v1.3.0
|
||||||
github.com/golang/protobuf v1.4.3 // indirect
|
|
||||||
github.com/google/uuid v1.2.0
|
|
||||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
|
||||||
github.com/kr/pretty v0.3.0 // indirect
|
|
||||||
github.com/muesli/clusters v0.0.0-20200529215643-2700303c1762
|
github.com/muesli/clusters v0.0.0-20200529215643-2700303c1762
|
||||||
github.com/muesli/kmeans v0.3.0
|
github.com/muesli/kmeans v0.3.0
|
||||||
github.com/rogpeppe/go-internal v1.8.0 // indirect
|
github.com/rclone/rclone v1.63.0
|
||||||
github.com/tealeg/xlsx v1.0.5
|
github.com/tealeg/xlsx v1.0.5
|
||||||
golang.org/x/crypto v0.0.0-20220208233918-bba287dce954 // indirect
|
gonum.org/v1/gonum v0.11.0
|
||||||
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
|
|
||||||
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 // indirect
|
|
||||||
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
|
|
||||||
gonum.org/v1/gonum v0.9.3
|
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
|
||||||
gopkg.in/yaml.v2 v2.3.0 // indirect
|
|
||||||
xorm.io/core v0.7.3
|
xorm.io/core v0.7.3
|
||||||
xorm.io/xorm v1.2.5
|
xorm.io/xorm v1.2.5
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
// Copyright 2023 The casbin Authors. All Rights Reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
_ "github.com/rclone/rclone/backend/all"
|
||||||
|
"github.com/rclone/rclone/fs"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getFs(bucketName string) (fs.Fs, error) {
|
||||||
|
f, err := fs.NewFs(context.Background(), bucketName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return f, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ListObjects2(bucketName string, prefix string) ([]fs.DirEntry, error) {
|
||||||
|
if bucketName == "" {
|
||||||
|
return nil, fmt.Errorf("bucket name is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := getFs(bucketName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
entries, err := f.List(context.Background(), prefix)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func PutObject2(bucketName string, key string, in io.Reader) error {
|
||||||
|
f, err := getFs(bucketName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use Rcat to put an object to the remote
|
||||||
|
//_, err = operations.Rcat(context.Background(), f, key, nil, nil, nil)
|
||||||
|
print(f)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteObject2(bucketName string, key string) error {
|
||||||
|
f, err := getFs(bucketName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
remoteObj, err := f.NewObject(context.Background(), key)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return remoteObj.Remove(context.Background())
|
||||||
|
}
|
Loading…
Reference in New Issue