gifs/api
gifs/api/context.go
Simplify upload. Simplify the upload code by not running the hashing async, which requires fewer copy operations and less channel synchronization. Also, take advantage of the fact that PipeWriters and PipeReaders will return an error to the PipeReaders/PipeWriters (respectively) when read/write is called (respectively) to avoid passing back errors through channels.
1 package api
3 import (
4 "code.google.com/p/goauth2/oauth/jwt"
5 "code.google.com/p/google-api-go-client/storage/v1beta2"
6 _ "github.com/go-sql-driver/mysql"
7 )
9 type Context struct {
10 Storage Storage
11 Datastore Datastore
12 UsageTracker *UsageTracker
13 Bucket string
14 RootDomain string
15 }
17 func NewMemStorage() Storage {
18 return Memstorage{}
19 }
21 func NewMemDatastore() Datastore {
22 return &Memstore{
23 collections: map[string]Collection{},
24 domains: map[string]Domain{},
25 items: map[string]Item{},
26 users: map[string]User{},
27 }
28 }
30 func NewGCSStorage(gcsClientEmail, gcsTokenURI string, gcsPemBytes []byte) (Storage, error) {
31 t := jwt.NewToken(gcsClientEmail, storage.DevstorageFull_controlScope, gcsPemBytes)
32 t.ClaimSet.Aud = gcsTokenURI
33 transport, err := jwt.NewTransport(t)
34 if err != nil {
35 return nil, err
36 }
37 client := transport.Client()
38 gcsService, err := storage.New(client)
39 if err != nil {
40 return nil, err
41 }
42 return &GoogleCloudStorage{gcsService}, nil
43 }