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.
go get github.com/goh-chunlin/go-onedrive
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 := onedrive.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.
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.
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
- Items
- Get individual item
- Copy
- Delete
- Move
- Rename
- Upload simple item size < 4MB
- Upload and then replace with item size < 4MB
Special thanks go to the following projects for providing useful references which help me in the development of this library.
This library is distributed under the GPL-3.0 License found in the LICENSE file.