owo

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2017 License: MIT Imports: 16 Imported by: 0

README

go-owo

Install

  1. Gain an API key in order to be actually able to use the service.
    1. If you want to just use the CLI go here and download it for your system.
    2. Run the command go get -u github.com/whats-this/owo.go/..., this should get the library and build/install latest CLI.
  2. Check the CLI to learn how to use the library.

gowo - CLI for owo

This is an example of how to use the library and also serves as a neat CLI. You can find built binaries here. To use the binaries you need owo key in a config file. By default it looks for a config file named .gowo.yaml (other formats also applicable, but not tested) in $HOME & ./ (current working directory) Currently gowo only cares about key and cdn, respectively key is the api key provided to you by service admins and cdn is the domain your uploaded files will be prefixed with.

Contribute

  • Fork this repository
  • Create a new feature branch for a new functionality or bugfix
  • Commit your changes
  • Execute test suite
  • Push your code and open a new pull request
  • Use issues for any questions
  • Check wiki for extra documentation

Contact

Documentation

Index

Constants

View Source
const APIRoot = "https://api.awau.moe"

APIRoot defines base url for the service's API endpoints

View Source
const FileCountLimit = 3

FileCountLimit defines a set limit of number of files to allow for pre-flight check before uploading the files

View Source
const FileUploadLimit = 83886080

FileUploadLimit defines a set limit for pre-flight check before uploading files

Variables

View Source
var (
	// APIFileUploadURL to send POSTs with files to
	APIFileUploadURL = APIRoot + "/upload/pomf"
	// APIShortenURL to send GETs with urls to
	APIShortenURL = APIRoot + "/shorten/polr"

	// CDNs represnts a list of CDNs available as of 04/01/2017
	CDNs = []string{
		"https://owo.whats-th.is/",
		"https://i.am-a.ninja/",
		"https://buttsare.sexy/",
		"https://nyanyanya.moe/",
		"https://all.foxgirlsare.sexy/",
		"https://i.stole-a-me.me/",
		"https://can-i-ask-dean-on-a.date/",
		"https://this.is-a.dog/",
		"https://deanis.sexy/",
	}
)

Functions

func SetKey

func SetKey(k string)

SetKey changes global client's API key

func ShortenURL

func ShortenURL(ctx context.Context, url string) (shortened string, err error)

ShortenURL shortens a single url using the global client

func ShortenURLs

func ShortenURLs(ctx context.Context, urls []string) (shortened []string, err error)

ShortenURLs shortens multiple urls using the global client

Types

type Client

type Client struct {
	Key    string
	Domain string
	// contains filtered or unexported fields
}

Client stores http client and key

func (*Client) ShortenURL

func (o *Client) ShortenURL(ctx context.Context, u string) (shortened string, err error)

ShortenURL shortens a single url

func (*Client) ShortenURLs

func (o *Client) ShortenURLs(ctx context.Context, urls []string) (shortened []string, err error)

ShortenURLs shortens multiple urls

func (*Client) UploadFile

func (o *Client) UploadFile(ctx context.Context, r NamedReader) (response *Response, err error)

UploadFile uploads a file

func (*Client) UploadFiles

func (o *Client) UploadFiles(ctx context.Context, rs []NamedReader) (response *Response, err error)

UploadFiles uploads multiple files using the global client

type ErrFileTooBig

type ErrFileTooBig struct {
	Filename string
	Filesize uint64
}

ErrFileTooBig thrown when file exceeds hardcoded filesize limit

func (ErrFileTooBig) Error

func (e ErrFileTooBig) Error() string

type ErrTooManyFiles added in v1.2.2

type ErrTooManyFiles struct {
	Count int
}

ErrTooManyFiles thrown when file count in upload exceeds filecount limit

func (ErrTooManyFiles) Error added in v1.2.2

func (e ErrTooManyFiles) Error() string

type ErrUploadFailed added in v1.3.0

type ErrUploadFailed struct {
	Message   string
	ErrorCode int
}

ErrUploadFailed thrown when success flag on response is false

func (ErrUploadFailed) Error added in v1.3.0

func (e ErrUploadFailed) Error() string

type File

type File struct {
	Hash        string `json:"hash,omitempty"`
	Name        string `json:"name,omitempty"`
	URL         string `json:"url,omitempty"`
	Size        int    `json:"size,omitempty"`
	Error       bool   `json:"error,omitempty"`
	Errorcode   int    `json:"errorcode,omitempty"`
	Description string `json:"description,omitempty"`
}

File represents a single file from json response (if there were no errors)

func (File) WithCDN

func (f File) WithCDN(cdn string) (string, error)

WithCDN returns file url prefixed with the CDN

type NamedReader

type NamedReader struct {
	Reader   io.Reader
	Filename string
}

NamedReader wrapper for a single file to upload

func FilesToNamedReaders

func FilesToNamedReaders(names []string) (files []NamedReader, err error)

FilesToNamedReaders Converts a list of file names to named readers.

type Response

type Response struct {
	Success     bool   `json:"success"`
	Errorcode   int    `json:"errorcode"`
	Description string `json:"description"`
	Files       []File `json:"files"`
}

Response contains json marshalled response from owo

func UploadFile

func UploadFile(ctx context.Context, r NamedReader) (response *Response, err error)

UploadFile uploads a file using the global client

func UploadFiles

func UploadFiles(ctx context.Context, rs []NamedReader) (response *Response, err error)

UploadFiles uploads multiple files using the global client

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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