39 lines
704 B
Go
39 lines
704 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"log"
|
|
"net"
|
|
"net/http"
|
|
|
|
"git.wntrmute.dev/kyle/goutils/config"
|
|
"git.wntrmute.dev/kyle/goutils/die"
|
|
"git.wntrmute.dev/kyle/kls/links"
|
|
)
|
|
|
|
var defaultConfigFile = config.DefaultConfigPath("kls", "kls.conf")
|
|
|
|
func main() {
|
|
|
|
cfgFile := flag.String("f", defaultConfigFile, "`path` to config file")
|
|
flag.Parse()
|
|
|
|
err := config.LoadFile(*cfgFile)
|
|
die.If(err)
|
|
|
|
ctx := context.Background()
|
|
db, err := links.Connect(ctx)
|
|
die.If(err)
|
|
|
|
srv := &server{db: db}
|
|
http.Handle("/", srv)
|
|
|
|
addr := net.JoinHostPort(
|
|
config.Get("HTTP_ADDR"),
|
|
config.GetDefault("HTTP_PORT", "8000"),
|
|
)
|
|
log.Print("listening on ", addr)
|
|
log.Fatal(http.ListenAndServe(addr, nil))
|
|
}
|