Git Product home page Git Product logo

go-onedrive's Introduction

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.

go-onedrive's People

Contributors

goh-chunlin avatar pekacprowicz avatar tixwho avatar tonimelisma avatar vishishtk avatar yoav85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

go-onedrive's Issues

Remove file

Hi,

I have encountered a problem when trying to delete file from OneDrive. Delete function reports no errors, however the file remains unchanged in OneDrive.

I belive that function Delete in DriveItemsService may be missing a Do action - there is only a creation of a request and it's not executed afterwards (like in the other functions such as Rename).

Kind regards :-)

Download file

What is the recommended way to download a file? Is there a method for file download or we should use Item's DownloadURL and fetch the file?

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.