Skip to content

Instantly share code, notes, and snippets.

@abhi-bit
Created March 22, 2014 03:24
Show Gist options
  • Save abhi-bit/9700635 to your computer and use it in GitHub Desktop.
Save abhi-bit/9700635 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"fmt"
"log"
"runtime"
"github.com/azer/atlas"
)
const (
VERSION = "1.0.0"
)
var (
address string
port int
syncWrites bool
dbPath string
db *QDB
totalEnqueues int
totalDequeues int
totalEmpties int
)
var api = atlas.New(atlas.Map{
"/enqueue": Enqueue,
"/version": Version,
"/": HealthCheck,
})
func Enqueue(request *atlas.Request) *atlas.Response{
if !request.POST {
return atlas.Error(405, "Not a POST request")
}
log.Printf("%#v\n", request)
return atlas.Success(request.Query)
}
func Version(request *atlas.Request) *atlas.Response {
return atlas.Success(VERSION)
}
func HealthCheck(request *atlas.Request) *atlas.Response{
return atlas.Success(1)
}
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
flag.StringVar(&address, "address", "", "Address to listen on. Default is all.")
flag.IntVar(&port, "port", 11311, "Port to listen on. Default is 11311.")
flag.BoolVar(&syncWrites, "sync", true, "Synchronize database writes")
flag.StringVar(&dbPath, "path", "db", "Database path. Default is db in current directory.")
flag.Parse()
}
func main() {
log.Printf("Listening on %s:%d\n", address, port)
log.Printf("DB Path: %s\n", dbPath)
db = NewQDB(dbPath, syncWrites)
log.Println("Ready...")
api.Start(":11311")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment