Refactor into package structure

This commit is contained in:
2020-11-11 01:46:48 +01:00
parent 04fa50d9ae
commit 27993e9fa0
13 changed files with 329 additions and 179 deletions

36
cmd/lookbuilding/main.go Normal file
View File

@ -0,0 +1,36 @@
package main
import (
"fmt"
"net/http"
"os"
l "hulthe.net/lookbuilding/internal/pkg/logging"
"hulthe.net/lookbuilding/internal/pkg/worker"
)
const EnvAddr = "LOOKBUILDING_ADDR"
func main() {
addr, isPresent := os.LookupEnv(EnvAddr)
if !isPresent {
addr = "0.0.0.0:8000"
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
worker.TriggerScan()
fmt.Fprintf(w, "OK")
})
fs := http.FileServer(http.Dir("static/"))
http.Handle("/static/", http.StripPrefix("/static/", fs))
l.Logger.Infof(`listening on %s`, addr)
go worker.Worker()
err := http.ListenAndServe(addr, nil)
if err != nil {
panic(err)
}
}