import "secondbit.org/gifs/api"
const (
DefaultTokenURI = "https://accounts.google.com/o/oauth2/token"
DefaultListenAddr = ":8080"
AuthHeader = "Gifs-Username"
)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(w http.ResponseWriter, r *http.Request, c Context)func CreateCollection(w http.ResponseWriter, r *http.Request, c Context)func GetBlob(w http.ResponseWriter, r *http.Request, c Context)func GetDomainMuxer(c Context) *mux.Routerfunc GetPathMuxer(c Context) *mux.Routerfunc Upload(id, collection, tag string, r io.Reader, c Context) (string, error)func UploadHandler(w http.ResponseWriter, r *http.Request, c Context)type Authorizer interface {
Authorize(token string, c Context) (string, error)
}type Bucket map[string][]bytetype Collection struct {
Items map[string]Item
Name string
Slug string
}type Context struct {
Storage Storage
Datastore Datastore
UsageTracker *UsageTracker
Authorizer Authorizer
Bucket string
RootDomain string
}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() Datastorefunc NewMySQLDatastore(dsn string) (Datastore, error)type GoogleCloudStorage struct {
*storage.Service
}func (gcs *GoogleCloudStorage) Delete(bucket, tmp string) errorfunc (gcs *GoogleCloudStorage) Download(bucket, id string, w io.Writer, c Context) (int64, error)func (gcs *GoogleCloudStorage) Move(srcBucket, src, dstBucket, dst string, c Context) errorfunc (gcs *GoogleCloudStorage) Upload(bucket, tmp string, r io.Reader, c Context, errs chan error, done chan struct{})type GoogleOAuth2Authorizer struct {
ClientID string
sync.Mutex
// contains filtered or unexported fields
}func NewGoogleOAuth2Authorizer(id string) *GoogleOAuth2Authorizerfunc (g *GoogleOAuth2Authorizer) Authorize(token string, c Context) (string, error)type Handler func(w http.ResponseWriter, r *http.Request, c Context)type Item struct {
Blob string
Bucket string
Tag string
}type Memstorage map[string]Bucketfunc (m Memstorage) Delete(bucket, tmp string) errorfunc (m Memstorage) Download(bucket, id string, w io.Writer, c Context) (int64, error)func (m Memstorage) Move(srcBucket, src, dstBucket, dst string, c Context) errorfunc (m Memstorage) Upload(bucket, tmp string, r io.Reader, c Context, errs chan error, done chan struct{})type Memstore map[string]*Collectionfunc (m Memstore) AddItemToCollection(slug string, item Item) errorfunc (m Memstore) CreateCollection(slug, name string) (Collection, error)func (m Memstore) GetCollectionData(slug string) (Collection, error)func (m Memstore) GetCollectionItems(slug string) (map[string]Item, error)func (m Memstore) GetItemFromCollection(slug, tag string) (Item, error)func (m Memstore) Init(dbName string) errorfunc (m Memstore) UpdateCollection(slug, name string) errortype SQLStore sql.DBfunc (s *SQLStore) AddItemToCollection(slug string, item Item) errorfunc (s *SQLStore) CreateCollection(slug, name string) (Collection, error)func (s *SQLStore) GetCollectionData(slug string) (Collection, error)func (s *SQLStore) GetCollectionItems(slug string) (map[string]Item, error)func (s *SQLStore) GetItemFromCollection(slug, tag string) (Item, error)func (s *SQLStore) Init(name string) errorfunc (s *SQLStore) UpdateCollection(slug, name string) errortype 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(gcsClientEmail, gcsTokenURI string, gcsPemBytes []byte) (Storage, error)func NewMemStorage() Storagetype Usage struct {
UploadedBytes int64
UploadBytesChan chan int64
DownloadedBytes int64
DownloadBytesChan chan int64
UploadRequests int64
UploadRequestsChan chan int64
DownloadRequests int64
DownloadRequestsChan chan int64
}type UsageTracker struct {
sync.Mutex
// contains filtered or unexported fields
}func NewUsageTracker() *UsageTrackerfunc (u *UsageTracker) TrackDownloads(id string) (bytes, requests chan int64)func (u *UsageTracker) TrackUploads(id string) (bytes, requests chan int64)Generated by godoc2md