Skip to content

putdotio/go-putio

 
 

Repository files navigation

Golang CI Linter Golang Tests

putio

putio is a Go client library for accessing the Put.io API v2.

Documentation

Available on GoDoc

Install

go get github.com/putdotio/go-putio@latest
go get golang.org/x/oauth2@latest

Usage

package main

import (
        "fmt"
        "log"
        "context"

        "golang.org/x/oauth2"
        "github.com/putdotio/go-putio"
)

func main() {
    oauthToken := "<YOUR-TOKEN-HERE>"
    tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: oauthToken})
    oauthClient := oauth2.NewClient(context.TODO(), tokenSource)

    client := putio.NewClient(oauthClient)

    const rootDir = 0
    root, err := client.Files.Get(context.TODO(), rootDir)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(root.Name)
}