-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (37 loc) · 1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"flag"
"net/http"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/romanbakaleyko/gopain/api/web"
"github.com/romanbakaleyko/gopain/storage"
log "github.com/sirupsen/logrus"
)
var (
storageType = flag.String("storage", "", "--storage slite")
dbPath = flag.String("path", "", "storage/storage.db")
)
func main() {
flag.Parse()
var routes *mux.Router
switch *storageType {
case "sqlite":
sqliteStorage, err := storage.NewSqliteStorage(*dbPath)
if err != nil {
log.Fatal(errors.Wrap(err, "couldn't set up sqlite storage"))
}
routes = web.CreateRoutes(web.NewHandler(sqliteStorage))
case "filestorage":
fs, err := storage.NewFileStorage(*dbPath)
if err != nil {
log.Fatal(errors.Wrap(err, "couldn't set up file storage"))
}
routes = web.CreateRoutes(web.NewHandler(fs))
default:
log.Fatal("couldn't set up a storage, no storage specified")
}
if err := http.ListenAndServe(":8000", routes); err != nil {
log.Fatal(err)
}
}