cabinet/main.go

51 lines
1.2 KiB
Go
Raw Permalink Normal View History

2019-10-30 15:31:07 +00:00
package main
import (
"flag"
"os"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
2019-11-11 00:26:36 +00:00
"code.chrissexton.org/cws/cabinet/auth"
2019-10-30 20:19:35 +00:00
"code.chrissexton.org/cws/cabinet/db"
"code.chrissexton.org/cws/cabinet/entry"
2019-10-30 20:19:35 +00:00
"code.chrissexton.org/cws/cabinet/web"
2019-10-30 15:31:07 +00:00
_ "github.com/mattn/go-sqlite3"
)
var (
2019-11-11 00:26:36 +00:00
dbPath = flag.String("db", "cabinet.db", "path to db")
httpAddr = flag.String("httpAddr", "0.0.0.0:8080", "http address")
salt = flag.String("salt", "c4b1n3t", "salt for IDs")
minHashLen = flag.Int("minHashLen", 4, "minimum ID hash size")
develop = flag.Bool("develop", false, "turn on develop mode")
adminSecret = flag.String("adminSecret", "helpme123", "secret for user creation")
2019-10-30 15:31:07 +00:00
)
func main() {
flag.Parse()
log.Logger = log.Logger.Output(zerolog.ConsoleWriter{Out: os.Stderr})
zerolog.SetGlobalLevel(zerolog.DebugLevel)
db, err := db.New(*dbPath)
if err != nil {
log.Fatal().
Err(err).
Msg("could not connect to database")
}
2019-11-03 20:01:24 +00:00
tx := db.MustBegin()
if err := entry.PrepareTable(tx); err != nil {
log.Fatal().Err(err).Msg("could not create database")
}
if err = auth.PrepareTable(tx); err != nil {
log.Fatal().Err(err).Msg("could not create database")
}
2019-11-03 20:01:24 +00:00
tx.Commit()
s := web.New(*httpAddr, db, FS(*develop))
2019-10-30 15:31:07 +00:00
s.Serve()
}