Yandex.Disk API client | REST API
go get github.com/ilyabrin/disk
package main
import (
"context"
"log"
"github.com/ilyabrin/disk"
)
func main() {
ctx := context.Background()
client := disk.New("YOUR_ACCESS_TOKEN")
disk, errorResponse := client.Disk.Info(ctx, nil)
if errorResponse != nil {
log.Fatal(errorResponse)
}
log.Println(disk)
}
Full documentation available here
// Disk information
client.Disk.Info()
// Remove resource
client.Resources.Delete(ctx, "path_to_file", false, nil)
// Get meta information
client.Resources.Meta(ctx, "path_to_file", nil)
// Update meta information
newMeta := &disk.Metadata{
"custom_properties": {
"key": "value",
"foo": "bar",
"platform": "linux",
},
}
client.Resources.UpdateMeta(ctx, "path_to_file", newMeta)
// Create directory
client.Resources.CreateDir(ctx, "path_to_file", nil)
// Copy resource
client.Resources.Copy(ctx, "path_to_file", "copy_here", nil)
// Get download link for resource
client.Resources.DownloadURL(ctx, "name_for_uploaded_file", nil)
// Get list of sorted files
client.Resources.GetSortedFiles(ctx, nil)
// List of last uploaded files
client.Resources.ListLastUploaded(ctx, nil)
// Move resource or rename it
client.Resources.Move(ctx, "path_to_file", "move_here", nil)
// List all public links
client.Resources.ListPublic(ctx, nil)
// Publish resource
client.Resources.Publish(ctx, "path_to_file", nil)
// Unpublish resource
client.Resources.Unpublish(ctx, "path_to_file", nil)
// Get link for ipload new file to Disk
client.Resources.GetUploadLink(ctx, "path_to_file")
// Upload new file to Disk
client.Resources.Upload(ctx, "local_file_path", "link_from_GetUploadLink", nil)
// Upload file from Internet
client.Resources.UploadFromURL(ctx, "filename_you_want", "url_to_file", nil)
// Get metadata for public resource
client.Public.Meta(ctx, "full_url_to_file", nil)
// Get link for download public resource
client.Public.DownloadURL(ctx, "full_url_to_file", nil)
// Save public file to Disk
client.Public.Save(ctx, "full_url_to_file", nil)
// Delete file from trash
client.Trash.Delete(ctx, "path_to_file", nil)
// Restore file from trash
client.Trash.Restore(ctx, "path_to_file", nil)
// List all resources OR all about resource in Trash
client.Trash.List(ctx, "/", nil)
// Get operation status
client.Operations.Status(ctx, "operation_id_string", nil)
Licensed under the MIT License, Copyright © 2020-present Ilya Brin