fileio

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2017 License: MIT Imports: 9 Imported by: 0

README

File.io

GoDoc Build Status Code Coverage Go Report Card

Golang interface for uploading or downloading files with file.io.

Installation
$ go get -u github.com/rvflash/fileio
Usage
Upload a file
key, err := fileio.Upload("/data/file.txt")
Upload a file with an expiration date (5 days in this example)
key, err := fileio.UploadWithExpire("/data/file.txt", 5)
Download a file
err := fileio.Download("2ojE41", "/tmp/file.txt")

Documentation

Index

Examples

Constants

View Source
const DefaultExpires = 14

DefaultExpires is the default number of days until the file will be deleted by File.io.

Variables

View Source
var URL = "https://file.io"

URL is by default the url of the File.io API.

Functions

func Download

func Download(key, file string) (err error)

Download downloads the file behind the key to the given file. An error occurs if the key does not exist or if the file fails to be create.

func Upload

func Upload(file string) (string, error)

Upload uploads a file to file.io and returns its key or an error if it can not. A default expires of 14 days is internally used.

Example
package main

import (
	"fmt"

	"github.com/rvflash/fileio"
)

func main() {
	key, err := fileio.Upload("test.txt")
	if err != nil {
		panic(err)
	}
	if err := fileio.Download(key, "/tmp/test.txt"); err != nil {
		panic(err)
	}
	fmt.Println("Yeah, good boy.")
}
Output:

Yeah, good boy.

func UploadWithExpire

func UploadWithExpire(file string, days int) (string, string, error)

UploadWithExpire uploads a file to file.io and sets the expires in days. It returns its key, the expiry duration and an error if it can not to get it.

Types

type Response

type Response struct {
	Success bool   `json:"success"`
	Code    int    `json:"error,omitempty"`
	Err     string `json:"message,omitempty"`
	Expiry  string `json:"expiry,omitempty"`
	Key     string `json:"key,omitempty"`
}

Response contains a FileIO response.

Jump to

Keyboard shortcuts

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