diff options
| author | Pablo M. Bermudo Garay <pablombg@gmail.com> | 2022-02-09 23:33:10 +0100 |
|---|---|---|
| committer | Pablo M. Bermudo Garay <pablombg@gmail.com> | 2022-02-10 14:38:48 +0100 |
| commit | 607eca65897dc15307d09fcc78e168affb03cfc4 (patch) | |
| tree | 2ebd137abba089ed84db1e3318faf031043daa00 /main.go | |
| parent | a92f55e2ce14ddf3b8d115f3740b0f88aee8b149 (diff) | |
Add config options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 28 |
1 files changed, 23 insertions, 5 deletions
@@ -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) } |
