summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go28
1 files changed, 23 insertions, 5 deletions
diff --git a/main.go b/main.go
index 36f51e4..e6ce9f6 100644
--- a/main.go
+++ b/main.go
@@ -6,6 +6,8 @@ package main
import (
"errors"
+ "flag"
+ "fmt"
"io/ioutil"
"log"
"net/http"
@@ -19,9 +21,15 @@ type storehouse struct {
objects objectstore.ObjectStore
}
-func InitStorehouse() *storehouse {
- // objects := objectstore.NewMemBackend()
- objects := objectstore.NewFileBackend("data")
+func InitStorehouse(memory bool, dataDir string) *storehouse {
+ var objects objectstore.ObjectStore
+
+ if memory {
+ objects = objectstore.NewMemBackend()
+ } else {
+ objects = objectstore.NewFileBackend(dataDir)
+ }
+
return &storehouse{objects: objects}
}
@@ -98,8 +106,17 @@ func (s *storehouse) deleteObject(c echo.Context) error {
}
func main() {
+ // Command-line options
+ memHelp := "Memory backend with de-duplication (default: file backend w/o de-dup)"
+ memory := flag.Bool("memory", false, memHelp)
+ dataDirHelp := "The directory where the objects are stored with the file backend"
+ dataDir := flag.String("datadir", "data", dataDirHelp)
+ portHelp := "The port on which the server will listen for connections"
+ port := flag.Int("port", 8080, portHelp)
+ flag.Parse()
+
// Initialization
- s := InitStorehouse()
+ s := InitStorehouse(*memory, *dataDir)
e := echo.New()
// Routes
@@ -108,5 +125,6 @@ func main() {
e.DELETE("/objects/:bucketId/:objectId", s.deleteObject)
// Start server
- e.Start(":8080")
+ listenConf := fmt.Sprintf(":%v", *port)
+ e.Start(listenConf)
}