drive

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 8 Imported by: 3

Documentation

Overview

Package drive is the Deta Drive service package.

The following is a simple Put operation example.

import (
	"bufio"
	"fmt"
	"os"

	"github.com/deta/deta-go/deta"
	"github.com/deta/deta-go/service/drive"
)

func main() {
	// Create a new Deta instance with a project key
	d, err := deta.New(deta.WithProjectKey("project_key"))
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create new Deta instance:%v\n", \n)
		os.Exit(1)
	}

	// Create a new Drive instance called "drawings", provide the previously created Deta instance
	drawings, err := drive.New(d, "drawings")
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create new Drive instance: %v\n", err)
		os.Exit(1)
	}

	// Open local file "art.svg"
	file, err := os.Open("./art.svg")
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to open file: %v\n", err)
		os.Exit(1)
	}
	defer file.Close()

	// Put "art.svg" to "drawings"
	name, err := drawings.Put(&drive.PutInput{
		Name:        "art.svg",
		Body:        bufio.NewReader(file),
		ContentType: "image/svg+xml",
	})
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to put file: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("successfully put file %s", name)
}

More examples and complete documentation on https://docs.deta.sh/docs/drive/sdk/

Package drive is the Deta Drive service package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeleteManyOutput

type DeleteManyOutput struct {
	Deleted []string          `json:"deleted"`
	Failed  map[string]string `json:"failed"`
}

DeleteManyOutput output for DeleteMany operation

type Drive

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

Drive is a Deta Drive service client that offers the API to make requests to Deta Drive

func New

func New(d *deta.Deta, driveName string) (*Drive, error)

New returns a pointer to new Drive

func (*Drive) Delete

func (d *Drive) Delete(name string) (string, error)

Delete a file from a Drive.

Returns name of file deleted (even if the file does not exist)

func (*Drive) DeleteMany

func (d *Drive) DeleteMany(names []string) (*DeleteManyOutput, error)

DeleteMany deletes multiple files in a Drive.

Deletes at most 1000 files in a single request. The file names should be a string slice. Returns a pointer to DeleteManyOutput.

func (*Drive) Get

func (d *Drive) Get(name string) (io.ReadCloser, error)

Get a file from the Drive.

Returns a io.ReadCloser for the file.

func (*Drive) List

func (d *Drive) List(limit int, prefix, last string) (*ListOutput, error)

List file names from the Drive.

List is paginated, returns the last name fetched, and the size if further pages are left. Provide the last name in the subsequent list operation to list remaining pages.

func (*Drive) Put

func (d *Drive) Put(i *PutInput) (string, error)

Put a file in the Drive.

Returns the name of file that was put in the drive.

type ListOutput

type ListOutput struct {
	// Pagination information
	Paging *paging `json:"paging"`
	// list of file names
	Names []string `json:"names"`
}

ListOutput output for List operation.

type PutInput

type PutInput struct {
	// name of file
	Name string
	// io.Reader with file content
	Body io.Reader
	// content type of file
	ContentType string
}

PutInput input for Put operation.

Jump to

Keyboard shortcuts

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