GithubHelp home page GithubHelp logo

niedbalski / files-sdk-go Goto Github PK

View Code? Open in Web Editor NEW

This project forked from files-com/files-sdk-go

0.0 1.0 0.0 472 KB

Files.com Official Go SDK. Files.com is Cloud Storage, Cloud Gateway, and MFT, All In One. Our built-in storage is fast, affordable, and available in 7 Worldwide Regions. Access Any File on Any Cloud via Files.com's Golang client, including Google, Amazon, Microsoft, Box, Dropbox, Amazon, Wasabi, Backblaze, Rackspace, and more.

Home Page: https://developers.files.com/

License: MIT License

Go 99.93% Shell 0.07%

files-sdk-go's Introduction

Files.com Go Client

The Files.com Go client library provides convenient access to the Files.com API from applications written in the Go language.

Installation

Make sure your project is using Go Modules (it will have a go.mod file in its root if it already is):

go mod init

Then, reference files-sdk-go in a Go program with import:

import (
    "github.com/Files-com/files-sdk-go"
    "github.com/Files-com/files-sdk-go/folder"
)

Run any of the normal go commands (build/install/test). The Go toolchain will resolve and fetch the files module automatically.

Documentation

Setting API Key

Setting by ENV

export FILES_API_KEY="XXXX-XXXX..."

Set Global Variable

import (
    "github.com/Files-com/files-sdk-go"
)

 files_sdk.APIKey = "XXXX-XXXX..."

Set Per Client

import (
    "github.com/Files-com/files-sdk-go"
    "github.com/Files-com/files-sdk-go/file"
)

config := files_sdk.Config{APIKey: "XXXX-XXXX..."}
client := file.Client{Config: config}

List

import (
	files_sdk "github.com/Files-com/files-sdk-go"
	folder "github.com/Files-com/files-sdk-go/folder"
    "fmt"
)

func main() {
    params := files_sdk.FolderListForParams{}
    it, err := folder.ListFor(params)

    if err != nil {
        // deal with error
    }

    for it.Next() {
        entry := it.Folder()
        fmt.Println(entry.Path)
    }
}

Upload a File

import (
	files_sdk "github.com/Files-com/files-sdk-go"
	file "github.com/Files-com/files-sdk-go/file"
)

func main() {
    client := file.Client{}
    uploadPath := "file-to-upload.txt"
    destinationPath := nil // Defaults to filename of uploadPath
    fileEntry, err := client.UploadFile(uploadPath, destinationPath)
    if err != nil {
        panic(err)
    }
}

Via io.Reader

import file "github.com/Files-com/files-sdk-go/file"

func main() {
    client := file.Client{}
    io := strings.NewReader("my file contents")
    destinationPath := "my-file.txt"
    fileEntry, err := client.Upload(io, destinationPath)
    if err != nil {
        panic(err)
    }
}

Download a File

import file "github.com/Files-com/files-sdk-go/file"

func main() {
    client := file.Client{}
    downloadPath := "file-to-download.txt"
    fileEntry, err := client.DownloadToFile(files_sdk.FileDownloadParams{Path: "file-to-download.txt"}, downloadPath)
    if err != nil {
        panic(err)
    }
}

files-sdk-go's People

Contributors

files-opensource-bot avatar niedbalski avatar bombino avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.