2019-10-30 15:31:07 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"code.chrissexton.org/cws/idea/web"
|
|
|
|
"code.chrissexton.org/cws/idea/db"
|
|
|
|
|
|
|
|
packr "github.com/gobuffalo/packr/v2"
|
|
|
|
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
dbPath = flag.String("db", "happy.db", "path to db")
|
|
|
|
httpAddr = flag.String("httpAddr", "0.0.0.0:8080", "http address")
|
|
|
|
salt = flag.String("salt", "happy", "salt for IDs")
|
|
|
|
minHashLen = flag.Int("minHashLen", 4, "minimum ID hash size")
|
|
|
|
develop = flag.Bool("develop", false, "turn on develop mode")
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
log.Logger = log.Logger.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
|
|
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
|
|
|
|
|
|
|
box := packr.New("dist", "frontend/dist")
|
|
|
|
log.Debug().Strs("dirlist", box.List()).Msg("packr made")
|
|
|
|
|
|
|
|
db, err := db.New(*dbPath)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal().
|
|
|
|
Err(err).
|
|
|
|
Msg("could not connect to database")
|
|
|
|
}
|
|
|
|
|
2019-10-30 15:37:45 +00:00
|
|
|
s := web.New(*httpAddr, "pub", db, box)
|
2019-10-30 15:31:07 +00:00
|
|
|
s.Serve()
|
|
|
|
}
|