/
main.go
62 lines (50 loc) · 1.37 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"log"
"github.com/bentrevor/calhoun/app"
"github.com/bentrevor/calhoun/db"
// presentation layers
"github.com/bentrevor/calhoun/cli"
"github.com/bentrevor/calhoun/web"
"github.com/namsral/flag"
)
func main() {
var (
rootDir string
assetPath string
srvPath string
ui string
)
flag.StringVar(&rootDir, "root-dir", "/home/vagrant/go/src/github.com/bentrevor/calhoun", "project root")
flag.StringVar(&assetPath, "asset-path", "web/assets", "asset path")
flag.StringVar(&srvPath, "srv-path", fmt.Sprintf("%s/images/srv", assetPath), "path to save uploaded files")
flag.StringVar(&ui, "ui", "web", "")
flag.Parse()
var server app.CalhounServer
postgresDB := db.NewPostgresDB("dev")
realFS := db.RealFS{RootDir: srvPath}
store := app.CalhounStore{DB: postgresDB, FS: realFS, SrvPath: srvPath}
calhoun := app.Calhoun{Store: store}
switch ui {
case "web":
calhoun.Renderer = web.BrowserRenderer{
ViewsPath: fmt.Sprintf("%s/web/views", rootDir),
PhotosPath: srvPath,
}
server = &web.WebServer{
App: calhoun,
AssetPath: assetPath,
FullAssetPath: fmt.Sprintf("%s/%s", rootDir, assetPath),
}
case "cli":
calhoun.Renderer = cli.ConsoleRenderer{}
server = cli.ConsoleServer{
App: calhoun,
Args: flag.Args(),
}
default:
log.Fatal(ui, " not supported")
}
app.Run("dev", server)
}