Refactor into package structure
This commit is contained in:
36
cmd/lookbuilding/main.go
Normal file
36
cmd/lookbuilding/main.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user