gifs/api

Paddy 2014-10-17 Child:03e846421572

7:21787ed8a185 Go to Latest

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.

History
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gifsd/etcd.go	Fri Oct 17 07:22:17 2014 -0400
     1.3 @@ -0,0 +1,50 @@
     1.4 +package main
     1.5 +
     1.6 +import (
     1.7 +	"log"
     1.8 +
     1.9 +	"code.secondbit.org/gifs/api"
    1.10 +	"github.com/coreos/go-etcd/etcd"
    1.11 +)
    1.12 +
    1.13 +func getEtcdContext(resp *etcd.Node) (api.Context, error) {
    1.14 +	var context api.Context
    1.15 +	var dsn, bucket, tmpbucket, domain string
    1.16 +	for _, node := range resp.Nodes {
    1.17 +		switch node.Key {
    1.18 +		case "/dsn":
    1.19 +			dsn = node.Value
    1.20 +		case "/bucket":
    1.21 +			bucket = node.Value
    1.22 +		case "/tmpbucket":
    1.23 +			tmpbucket = node.Value
    1.24 +		case "/domain":
    1.25 +			domain = node.Value
    1.26 +		}
    1.27 +	}
    1.28 +	if dsn != "" {
    1.29 +		log.Println("Using PostgreSQL as our datastore.")
    1.30 +		/*datastore, err := api.NewMySQLDatastore(dsn)
    1.31 +		if err != nil {
    1.32 +			return context, err
    1.33 +		}
    1.34 +		context.Datastore = datastore*/
    1.35 +		panic("PostgreSQL not implemented yet.")
    1.36 +	} else {
    1.37 +		log.Println("Using in-memory datastore.")
    1.38 +		context.Datastore = api.NewMemDatastore()
    1.39 +	}
    1.40 +	context.UsageTracker = api.NewMemTracker() // TODO: get this using influx
    1.41 +	context.Bucket = bucket
    1.42 +	context.TmpBucket = tmpbucket
    1.43 +	context.RootDomain = domain
    1.44 +	storage, err := api.NewGCSServiceStorage()
    1.45 +	if err != nil {
    1.46 +		log.Println("Using in-memory blob store.")
    1.47 +		context.Storage = api.NewMemStorage()
    1.48 +	} else {
    1.49 +		log.Println("Using Google Cloud Storage for blob store.")
    1.50 +		context.Storage = storage
    1.51 +	}
    1.52 +	return context, nil
    1.53 +}