summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChloe Kudryavtsev <toast@toast.cafe>2019-11-24 13:21:05 -0500
committerChloe Kudryavtsev <toast@toast.cafe>2019-11-24 13:21:05 -0500
commitf074aba145219dbeffb35b51e7757d14f8bf3305 (patch)
treed89f7e212e274df7e96459ed09fe00ebac31ce56
parentRemove more redundant comments (diff)
Allow for different future storage engines
-rw-r--r--main.go28
1 files changed, 19 insertions, 9 deletions
diff --git a/main.go b/main.go
index adce93e..b398fc5 100644
--- a/main.go
+++ b/main.go
@@ -14,32 +14,42 @@ import (
var S settings
type settings struct {
- Bind string
- Redis string
+ Bind string
+ Redis string
+ Storage string
}
func main() {
// ---- Flags
flag.StringVar(&S.Bind, "bind", ":8080", "address to bind to")
flag.StringVar(&S.Redis, "redis", "redis://localhost:6379", "redis connection string")
+ flag.StringVar(&S.Storage, "storage", "redis", "type of storage to use")
flag.Parse()
// ---- Storage system
- redisOpts, err := redis.ParseURL(S.Redis)
- if err != nil {
- fmt.Fprintf(os.Stderr, "Could not parse redis connection string %s\n", S.Redis)
+ var store storage.CHR
+
+ switch S.Storage {
+ case "redis":
+ redisOpts, err := redis.ParseURL(S.Redis)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Could not parse redis connection string %s\n", S.Redis)
+ os.Exit(1)
+ }
+ client := redis.NewClient(redisOpts)
+ store = (*storage.Redis)(client)
+ default:
+ fmt.Fprintf(os.Stderr, "Could not figure out which storage system to use, tried %s\n", S.Storage)
os.Exit(1)
}
- client := redis.NewClient(redisOpts)
- storage := (*storage.Redis)(client)
// ---- Is storage healthy?
- if !storage.Healthy() {
+ if !store.Healthy() {
fmt.Fprintf(os.Stderr, "Storage is unhealthy, cannot proceed.\n")
os.Exit(1)
}
// ---- Start!
- handler := http.GenHandler(storage)
+ handler := http.GenHandler(store)
fasthttp.ListenAndServe(S.Bind, handler)
}