gifs/api
2014-08-27
Child:eb450538f079
gifs/api/context.go
Spike out functionality and tests. Create our interfaces around storing data and retrieving it. Create an in-memory implementation of our interfaces, for testing and rapid dev purposes. Begin sketching out what our unit tests look like. Create our Google Cloud Storage datastore implementation. Sketch out an idea for a usage collection process to keep track of which users are actually using stuff.
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 }