-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnew_ftp.go
40 lines (36 loc) · 1.1 KB
/
new_ftp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package example
import (
"fmt"
"os"
ftp "go.beyondstorage.io/services/ftp"
"go.beyondstorage.io/v5/pairs"
"go.beyondstorage.io/v5/services"
"go.beyondstorage.io/v5/types"
)
func NewFTP() (types.Storager, error) {
return ftp.NewStorager(
// credential: https://beyondstorage.io/docs/go-storage/pairs/credential
//
// Credential could be fetched from service's console.
//
// Example Value: basic:user:password
pairs.WithCredential(os.Getenv("STORAGE_FTP_CREDENTIAL")),
// endpoint: https://beyondstorage.io/docs/go-storage/pairs/endpoint
//
// Example Value: tcp:host:port
pairs.WithEndpoint(os.Getenv("STORAGE_FTP_ENDPOINT")),
// work_dir: https://beyondstorage.io/docs/go-storage/pairs/work_dir
//
// Relative operations will be based on this WorkDir.
pairs.WithWorkDir(os.Getenv("STORAGE_FTP_WORKDIR")),
)
}
func NewFTPFromString() (types.Storager, error) {
str := fmt.Sprintf(
"ftp://%s?credential=%s&endpoint=%s",
os.Getenv("STORAGE_FTP_WORKDIR"),
os.Getenv("STORAGE_FTP_CREDENTIAL"),
os.Getenv("STORAGE_FTP_ENDPOINT"),
)
return services.NewStoragerFromString(str)
}