-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (39 loc) · 1.22 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
package main
import (
"flag"
"log"
"net/http"
"github.com/blkchain/blocks/daemon"
assetfs "github.com/elazarl/go-bindata-assetfs"
)
var (
assetsPath string
builtinAssets string // -ldflags -X only works with strings
)
func processFlags() *daemon.Config {
cfg := &daemon.Config{}
flag.StringVar(&cfg.ListenSpec, "listen", "localhost:3000", "HTTP listen spec")
flag.StringVar(&cfg.Db.ConnectString, "connstr", "host=/var/run/postgresql dbname=blocks sslmode=disable", "DB Connect String")
flag.StringVar(&assetsPath, "assets-path", "assets", "Path to assets dir")
flag.Parse()
return cfg
}
// When we are baking in assets, builtinAssets is not blank (set via
// ldflags, see Makefile). Otherwise they are read from assetpath.
func setupHttpAssets(cfg *daemon.Config) {
if builtinAssets != "" {
log.Printf("Running with builtin assets.")
cfg.UI.Assets = &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo, Prefix: builtinAssets}
} else {
log.Printf("Assets served from %q.", assetsPath)
cfg.UI.Assets = http.Dir(assetsPath)
cfg.UI.Babel = true
}
}
func main() {
cfg := processFlags()
setupHttpAssets(cfg)
if err := daemon.Run(cfg); err != nil {
log.Printf("Error in main(): %v", err)
}
}