Skip to content
This repository has been archived by the owner on Nov 30, 2019. It is now read-only.

secondbit/gifs-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

api

import "secondbit.org/gifs/api"

Constants

const (
    DefaultTokenURI   = "https://accounts.google.com/o/oauth2/token"
    DefaultListenAddr = ":8080"
    AuthHeader        = "Gifs-Username"
)

Variables

var (
    BucketNotFoundError = errors.New("bucket not found")
    BlobNotFoundError   = errors.New("blob not found")
)
var (
    CollectionNotFoundError = errors.New("collection not found")
)
var (
    InvalidBearerToken = errors.New("Invalid bearer token")
)

func CollectionList

func CollectionList(w http.ResponseWriter, r *http.Request, c Context)

func CreateCollection

func CreateCollection(w http.ResponseWriter, r *http.Request, c Context)

func GetBlob

func GetBlob(w http.ResponseWriter, r *http.Request, c Context)

func GetDomainMuxer

func GetDomainMuxer(c Context) *mux.Router

func GetPathMuxer

func GetPathMuxer(c Context) *mux.Router

func Upload

func Upload(id, collection, tag string, r io.Reader, c Context) (string, error)

func UploadHandler

func UploadHandler(w http.ResponseWriter, r *http.Request, c Context)

type Authorizer

type Authorizer interface {
    Authorize(token string, c Context) (string, error)
}

type Bucket

type Bucket map[string][]byte

type Collection

type Collection struct {
    Items map[string]Item
    Name  string
    Slug  string
}

type Context

type Context struct {
    Storage      Storage
    Datastore    Datastore
    UsageTracker *UsageTracker
    Authorizer   Authorizer
    Bucket       string
    RootDomain   string
}

type Datastore

type Datastore interface {
    Init(dbName string) error
    CreateCollection(slug, name string) (Collection, error)
    UpdateCollection(slug, name string) error
    GetCollectionData(slug string) (Collection, error)
    GetCollectionItems(slug string) (map[string]Item, error)
    AddItemToCollection(slug string, item Item) error
    GetItemFromCollection(slug, tag string) (Item, error)
}

func NewMemDatastore

func NewMemDatastore() Datastore

func NewMySQLDatastore

func NewMySQLDatastore(dsn string) (Datastore, error)

type GoogleCloudStorage

type GoogleCloudStorage struct {
    *storage.Service
}

func (*GoogleCloudStorage) Delete

func (gcs *GoogleCloudStorage) Delete(bucket, tmp string) error

func (*GoogleCloudStorage) Download

func (gcs *GoogleCloudStorage) Download(bucket, id string, w io.Writer, c Context) (int64, error)

func (*GoogleCloudStorage) Move

func (gcs *GoogleCloudStorage) Move(srcBucket, src, dstBucket, dst string, c Context) error

func (*GoogleCloudStorage) Upload

func (gcs *GoogleCloudStorage) Upload(bucket, tmp string, r io.Reader, c Context, errs chan error, done chan struct{})

type GoogleOAuth2Authorizer

type GoogleOAuth2Authorizer struct {
    ClientID string

    sync.Mutex
    // contains filtered or unexported fields
}

func NewGoogleOAuth2Authorizer

func NewGoogleOAuth2Authorizer(id string) *GoogleOAuth2Authorizer

func (*GoogleOAuth2Authorizer) Authorize

func (g *GoogleOAuth2Authorizer) Authorize(token string, c Context) (string, error)

type Handler

type Handler func(w http.ResponseWriter, r *http.Request, c Context)

type Item

type Item struct {
    Blob   string
    Bucket string
    Tag    string
}

type Memstorage

type Memstorage map[string]Bucket

func (Memstorage) Delete

func (m Memstorage) Delete(bucket, tmp string) error

func (Memstorage) Download

func (m Memstorage) Download(bucket, id string, w io.Writer, c Context) (int64, error)

func (Memstorage) Move

func (m Memstorage) Move(srcBucket, src, dstBucket, dst string, c Context) error

func (Memstorage) Upload

func (m Memstorage) Upload(bucket, tmp string, r io.Reader, c Context, errs chan error, done chan struct{})

type Memstore

type Memstore map[string]*Collection

func (Memstore) AddItemToCollection

func (m Memstore) AddItemToCollection(slug string, item Item) error

func (Memstore) CreateCollection

func (m Memstore) CreateCollection(slug, name string) (Collection, error)

func (Memstore) GetCollectionData

func (m Memstore) GetCollectionData(slug string) (Collection, error)

func (Memstore) GetCollectionItems

func (m Memstore) GetCollectionItems(slug string) (map[string]Item, error)

func (Memstore) GetItemFromCollection

func (m Memstore) GetItemFromCollection(slug, tag string) (Item, error)

func (Memstore) Init

func (m Memstore) Init(dbName string) error

func (Memstore) UpdateCollection

func (m Memstore) UpdateCollection(slug, name string) error

type SQLStore

type SQLStore sql.DB

func (*SQLStore) AddItemToCollection

func (s *SQLStore) AddItemToCollection(slug string, item Item) error

func (*SQLStore) CreateCollection

func (s *SQLStore) CreateCollection(slug, name string) (Collection, error)

func (*SQLStore) GetCollectionData

func (s *SQLStore) GetCollectionData(slug string) (Collection, error)

func (*SQLStore) GetCollectionItems

func (s *SQLStore) GetCollectionItems(slug string) (map[string]Item, error)

func (*SQLStore) GetItemFromCollection

func (s *SQLStore) GetItemFromCollection(slug, tag string) (Item, error)

func (*SQLStore) Init

func (s *SQLStore) Init(name string) error

func (*SQLStore) UpdateCollection

func (s *SQLStore) UpdateCollection(slug, name string) error

type Storage

type Storage interface {
    Upload(bucket, tmp string, r io.Reader, c Context, errs chan error, done chan struct{})
    Delete(bucket, tmp string) error
    Move(srcBucket, src, dstBucket, dst string, c Context) error
    Download(bucket, id string, w io.Writer, c Context) (int64, error)
}

func NewGCSStorage

func NewGCSStorage(gcsClientEmail, gcsTokenURI string, gcsPemBytes []byte) (Storage, error)

func NewMemStorage

func NewMemStorage() Storage

type Usage

type Usage struct {
    UploadedBytes        int64
    UploadBytesChan      chan int64
    DownloadedBytes      int64
    DownloadBytesChan    chan int64
    UploadRequests       int64
    UploadRequestsChan   chan int64
    DownloadRequests     int64
    DownloadRequestsChan chan int64
}

type UsageTracker

type UsageTracker struct {
    sync.Mutex
    // contains filtered or unexported fields
}

func NewUsageTracker

func NewUsageTracker() *UsageTracker

func (*UsageTracker) TrackDownloads

func (u *UsageTracker) TrackDownloads(id string) (bytes, requests chan int64)

func (*UsageTracker) TrackUploads

func (u *UsageTracker) TrackUploads(id string) (bytes, requests chan int64)

Generated by godoc2md

Releases

No releases published

Packages

No packages published