gifs/api
gifs/api/context.go
Upload is no longer async, memstorage is parallel-safe. Upload no longer needs to be run async (it can be run inside a goroutine), so it now returns stuff instead of taking a channel as an argument. This will make it easier to implement, as all the async stuff is an abstraction above, and therefore doesn't need to be worried about for each reimplementation. The memstorage type is no longer exported and can now be safely used by multiple goroutines, thanks to the sync package.
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 }