henwen/main.go

39 lines
975 B
Go
Raw Normal View History

2020-04-01 06:35:15 +00:00
package main
import (
"flag"
"log"
"net/http"
2020-10-11 23:55:27 +00:00
"time"
2020-04-01 06:35:15 +00:00
2020-10-11 18:21:17 +00:00
"gitlab.codemonkeysoftware.net/b/henwen/internal/back"
"gitlab.codemonkeysoftware.net/b/henwen/internal/front"
2020-04-01 06:35:15 +00:00
)
func main() {
addr := flag.String("address", ":8080", "bind address for HTTP server as host:port")
title := flag.String("title", "Henwen", "website title")
baseURL := flag.String("baseURL", "http://localhost:8080", "base URL for HTTP routes")
dbFileName := flag.String("db", "./henwen.db", "name of database file")
2020-10-11 23:55:27 +00:00
httpTimeout := flag.Int("httpTimeout", 5000, "HTTP server timeout in ms")
2020-04-01 06:35:15 +00:00
flag.Parse()
store, err := back.NewStore(*dbFileName, back.SecureGenString)
if err != nil {
log.Fatal(err)
}
srv := http.Server{
Addr: *addr,
Handler: front.NewHandler(front.HandlerParams{
Store: store,
Title: *title,
BaseURL: *baseURL,
2020-10-11 23:55:27 +00:00
Timeout: time.Millisecond * time.Duration(*httpTimeout),
2020-04-01 06:35:15 +00:00
}),
}
2020-04-01 06:40:34 +00:00
log.Println("Listening on", *addr)
2020-04-01 06:35:15 +00:00
log.Println(srv.ListenAndServe())
}