github.com/Files-com/files-sdk-go/v3@v3.1.81/README.md (about) 1 # Files.com Go Client 2 3 The Files.com Go client library provides convenient access to the Files.com API from applications written in the Go language. 4 5 6 ## Installation 7 8 Make sure your project is using Go Modules (it will have a `go.mod` file in its 9 root if it already is): 10 11 ``` sh 12 go mod init 13 ``` 14 15 Then, reference files-sdk-go in a Go program with `import`: 16 17 ``` go 18 import ( 19 "github.com/Files-com/files-sdk-go/v3" 20 "github.com/Files-com/files-sdk-go/v3/folder" 21 ) 22 ``` 23 24 Run any of the normal `go` commands (`build`/`install`/`test`). The Go 25 toolchain will resolve and fetch the files module automatically. 26 27 28 ## Documentation 29 30 31 ### Setting API Key 32 33 34 #### Setting by ENV 35 36 ``` sh 37 export FILES_API_KEY="XXXX-XXXX..." 38 ``` 39 40 41 #### Set Global Variable 42 43 ```go 44 import ( 45 "github.com/Files-com/files-sdk-go/v3" 46 ) 47 48 files_sdk.GlobalConfig.APIKey = "XXXX-XXXX..." 49 ``` 50 51 52 #### Set Per Client 53 54 ```go 55 import ( 56 "github.com/Files-com/files-sdk-go/v3" 57 "github.com/Files-com/files-sdk-go/v3/file" 58 ) 59 60 config := files_sdk.Config{APIKey: "XXXX-XXXX..."}.Init() 61 client := file.Client{Config: config} 62 ``` 63 64 65 ### List 66 67 ```go 68 import ( 69 files_sdk "github.com/Files-com/files-sdk-go/v3" 70 folder "github.com/Files-com/files-sdk-go/v3/folder" 71 "fmt" 72 ) 73 74 func main() { 75 it, err := folder.ListFor(files_sdk.FolderListForParams{}) 76 77 if err != nil { 78 // deal with error 79 } 80 81 for it.Next() { 82 entry := it.Folder() 83 fmt.Println(entry.Path) 84 } 85 } 86 87 ``` 88 89 90 ### Upload a File 91 92 ```go 93 import ( 94 files_sdk "github.com/Files-com/files-sdk-go/v3" 95 file "github.com/Files-com/files-sdk-go/v3/file" 96 ) 97 98 func main() { 99 client := file.Client{Config: files_sdk.GlobalConfig} 100 uploadPath := "file-to-upload.txt" 101 destinationPath := "file-to-upload.txt" 102 err := client.Upload(UploadWithFile(uploadPath), UploadWithDestinationPath(destinationPath)) 103 if err != nil { 104 panic(err) 105 } 106 } 107 ``` 108 109 110 #### Via io.Reader 111 112 ```go 113 import file "github.com/Files-com/files-sdk-go/v3/file" 114 115 func main() { 116 client := file.Client{Config: files_sdk.GlobalConfig} 117 io := strings.NewReader("my file contents") 118 destinationPath := "my-file.txt" 119 err := client.Upload(UploadWithReader(io), UploadWithDestinationPath(destinationPath)) 120 if err != nil { 121 panic(err) 122 } 123 } 124 ``` 125 126 127 ### Download a File 128 129 ```go 130 import file "github.com/Files-com/files-sdk-go/v3/file" 131 132 func main() { 133 client := file.Client{Config: files_sdk.GlobalConfig} 134 downloadPath := "file-to-download.txt" 135 fileEntry, err := client.DownloadToFile(files_sdk.FileDownloadParams{Path: "file-to-download.txt"}, downloadPath) 136 if err != nil { 137 panic(err) 138 } 139 } 140 ``` 141 142 143 ### Docker 144 145 ```shell 146 docker build . --tag files-sdk-go:latest 147 docker run --workdir /app --volume ${PWD}:/app -it files-sdk-go 148 ``` 149 150 151 ## Getting Support 152 153 The Files.com team is happy to help with any SDK Integration challenges you may face. 154 155 Just email support@files.com and we'll get the process started.