Go Onedrive Save

This is a Golang client library for accessing the Microsoft OneDrive REST API.

Project README

go-onedrive

Go Build CodeQL Scan Go Report Card Go Reference License: GPL v3 Donate

go-onedrive is a Golang client library for accessing the Microsoft OneDrive REST API.

This project is inspired by a few open-source projects, especially the go-github project from Google.

Currently, go-onedrive requires Golang version 1.15 or greater. go-onedrive tracks Golang version support policy. I'll do my best not to break older versions of Golang if I don't have to, but due to tooling constraints, I don't always test older versions.

Getting Started

Module support was introduced in Go 1.15. Starting from Go 1.16, module-aware mode is enabled by default. Hence, I'll assume the module-aware mode is enabled when using this library.

In the go.mod file, please make sure the correct package with the correct version is used.

...

require (
	github.com/goh-chunlin/go-onedrive v1.1.1
	...
)

The current latest version should be v1.1.1 (updated on 17th July 2021, as shown on the Releases page).

In other go source files, you can then import the go-onedrive library as follows.

import "github.com/goh-chunlin/go-onedrive/onedrive"

Construct a new OneDrive client, then use the various services on the client to access different parts of the OneDrive API. For example:

ctx := context.Background()
ts := oauth2.StaticTokenSource(
	&oauth2.Token{AccessToken: "..."},
)
tc := oauth2.NewClient(ctx, ts)

client := onedrive.NewClient(tc)

// list all OneDrive drives for the current logged in user
drives, err := client.Drives.List(ctx)

NOTE: Using the context package, one can easily pass cancelation signals and deadlines to various services of the client for handling a request. In case there is no context available, then context.Background() can be used as a starting point.

Authentication

The go-onedrive library does not directly handle authentication. Instead, when creating a new client, pass an http.Client that can handle authentication for you. The easiest and recommended way to do this is using the oauth2 library.

Note that when using an authenticated Client, all calls made by the client will include the specified OAuth token. Therefore, authenticated clients should almost never be shared between different users.

See the oauth2 docs for complete instructions on using that library.

Contributing

This library is being initially developed as a library for my personal project as listed below.

Hence, API methods will likely be implemented in the order that they are needed by my personal project. However, I still welcome you to contribute to this project to support the following features.

  • General
    • Async job to track progress
    • Search
  • Drives
    • Get default drive
    • Get individual drive
    • List all available drives
  • Folders
    • Create
    • Copy
    • Delete
    • List children (items)
    • Move
    • Rename
    • Create share link to a folder and its content
    • List share links of a folder
  • Items
    • Get individual item
    • Copy
    • Delete
    • Move
    • Rename
    • Create share link to an item
    • Delete share link (or permission) of an item
    • List share links of an item
    • Upload simple item size < 4MB
    • Upload and then replace with item size < 4MB
    • Upload large item without additional retry attempts

Sensei Projects

Special thanks go to the following projects for providing useful references which help me in the development of this library.

License

This library is distributed under the GPL-3.0 License found in the LICENSE file.

Open Source Agenda is not affiliated with "Go Onedrive" Project. README Source: goh-chunlin/go-onedrive
Stars
89
Open Issues
1
Last Commit
1 year ago
License

Open Source Agenda Badge

Open Source Agenda Rating