-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
51 lines (42 loc) · 943 Bytes
/
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
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"github.com/bakaoh/sqlite-gobroem/gobroem"
)
const version = "0.1.0"
var options struct {
db string
host string
port uint
}
// printHeader print the welcome header.
func printHeader() {
fmt.Fprintf(os.Stdout, "sqlite gobroem, v%s\n", version)
}
// initConfig parse CLI config
func initConfig() {
options.db = *flag.String("db", "test/test.db", "SQLite database file")
options.host = *flag.String("bind", "localhost", "HTTP server host")
options.port = *flag.Uint("listen", 8000, "HTTP server listen port")
flag.Parse()
}
// startServer initialize and start the web server.
func startServer() {
api, err := gobroem.NewAPI(options.db)
if err != nil {
log.Fatal("can not open db", err)
}
http.ListenAndServe(
fmt.Sprintf("%s:%d", options.host, options.port),
api.Handler("/", "/static/"),
)
}
func main() {
printHeader()
initConfig()
startServer()
}