gifs/api
2014-10-17
Child:03e846421572
gifs/api/gifsd/etcd.go
Create a Dockerfile and binary. Write a Dockerfile that compiles everything and runs it. Start the binary; load a Context from etcd, and start everything running. The binary is pretty useless until we get HTTP handlers, though, obviously.
1 package main
3 import (
4 "log"
6 "code.secondbit.org/gifs/api"
7 "github.com/coreos/go-etcd/etcd"
8 )
10 func getEtcdContext(resp *etcd.Node) (api.Context, error) {
11 var context api.Context
12 var dsn, bucket, tmpbucket, domain string
13 for _, node := range resp.Nodes {
14 switch node.Key {
15 case "/dsn":
16 dsn = node.Value
17 case "/bucket":
18 bucket = node.Value
19 case "/tmpbucket":
20 tmpbucket = node.Value
21 case "/domain":
22 domain = node.Value
23 }
24 }
25 if dsn != "" {
26 log.Println("Using PostgreSQL as our datastore.")
27 /*datastore, err := api.NewMySQLDatastore(dsn)
28 if err != nil {
29 return context, err
30 }
31 context.Datastore = datastore*/
32 panic("PostgreSQL not implemented yet.")
33 } else {
34 log.Println("Using in-memory datastore.")
35 context.Datastore = api.NewMemDatastore()
36 }
37 context.UsageTracker = api.NewMemTracker() // TODO: get this using influx
38 context.Bucket = bucket
39 context.TmpBucket = tmpbucket
40 context.RootDomain = domain
41 storage, err := api.NewGCSServiceStorage()
42 if err != nil {
43 log.Println("Using in-memory blob store.")
44 context.Storage = api.NewMemStorage()
45 } else {
46 log.Println("Using Google Cloud Storage for blob store.")
47 context.Storage = storage
48 }
49 return context, nil
50 }