gogledrive

package module
v0.0.0-...-c45525c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2020 License: GPL-3.0 Imports: 11 Imported by: 1

README

gogle-drive

A google's drive API consumer layer in go

This package aims to help consuming google's drive API through a layer that provides functionalities to easily use some of the provided capabilities. It connect to Google;s Drive through an OAuth Client.

Getting Started

Just import this package using

import github.com/mzampetakis/gogle-drive
First Use

Before running your application you must provide a valid json file with the google's API OAuth client ID.

Head to https://console.developers.google.com/apis/credentials/oauthclient and add Desktop App as Application type. Then provide a name to distinguish your app and press the Create button.

At the Google's Console Credentials page under the OAuth 2.0 Client IDs section you must download the client's credentials as a json file and move it into your project.

Consider adding this file to your .gitignore as well as the token.json that will be generated later on.

On the first run you will be prompted to authenticated your client through a web link. The output at the first run will prompt to visit a link, and after you allow the requested access, paste the provided token.

Go to the following link in your browser. 
https://accounts.google.com/o/oauth2/auth?.....

Then type here the authorization code: paste_here_the_provided_token

This will produce a token.json in your project's root directory.

Examples

A siple example that lists your google's drive files is provided in examples/gogledriveexample.go file.

To start a new gogledrive's instance simply call:

gdrive, err := gogledrive.New("path_to/credentials.json")

Then using the gdrive all provided methods are available.

To Search for files you can use

filterCriteria := gogledrive.ListFilter{}
assets, err := gdrive.SearchFiles(filterCriteria)

The gogledrive.ListFilter provides filters for file name, mime type and folderID to search within. For more details on filtering please refer to the official documentation here: https://developers.google.com/drive/api/v3/reference/query-ref

To get a specific file the method GetFile is available through

data, err := gdrive.GetFile("fileID")

You can review the whole package's documentation by running go doc -all . at this package's folder.

Contributing

You can contribute to this project by just opening a PR or open first an issue. Please describe thoroughly what are your PR solves or adds.

Some ideas for contribution:

  • upload a file
  • create a file
  • add more filter criteria
  • ...

Documentation

Overview

Package gogledrive provides some easy to use functionalities about the google drive such as searching for assets and downloading files. It uses the Google oAuth Client which can be generated from: https://console.developers.google.com/apis/credentials

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gogledrive

type Gogledrive struct {
	// contains filtered or unexported fields
}

func New

func New(credentialsFile string) (*Gogledrive, error)

New returns a new instance of gogledrive's. It uses the provided credentialsFile to connect to Google OAuth service.

func (*Gogledrive) GetFile

func (gdrive *Gogledrive) GetFile(fileID string) ([]byte, error)

GetFile returns a byte[] with the contents of the fileID provided

func (*Gogledrive) SearchFiles

func (gdrive *Gogledrive) SearchFiles(filters ListFilter) (map[string]string, error)

SearchFiles returns a map where key is the file name and value is the FileId that retrieves as search results based on the provided ListFilter

type ListFilter

type ListFilter struct {
	FolderID *string
	Name     *string
	MimeType *string
}

ListFilter provides the available filters for feedind the SearchFiles() Use mimeType = 'application/vnd.google-apps.folder' to list folders

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL