server/cmd/hbd/main.go
stephen mcquay 7818a64756 enable static asset serving
- It changes behavior depending on if STATIC is set.
- will need to run $(go generate ./...) before compiles will work
2015-08-26 23:16:12 -07:00

56 lines
1.3 KiB
Go

package main
import (
"flag"
"log"
"math/rand"
"net/http"
_ "net/http/pprof"
"os"
"runtime/pprof"
"time"
"hackerbots.us/server"
)
var addr = flag.String("addr", ":8666", "http service address")
var profile = flag.String("pprof", "", "if specified will run with pprof")
var mprofile = flag.String("mprof", "", "if specified will dump a memory profile")
var netprofile = flag.Bool("netprof", false, "if specified will run with net/http/pprof on :8667")
var verbose = flag.Bool("verbose", false, "")
var config = flag.String("config", "~/.config/hackerbots/server.json", "location of config file")
func main() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
log.Printf("Starting Server...")
var err error
rand.Seed(time.Now().UnixNano())
flag.Parse()
if *profile != "" {
f, err := os.Create(*profile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
}
if *netprofile {
go func() {
log.Println(http.ListenAndServe("localhost:8667", nil))
}()
log.Println("serving profile info at http://localhost:8667/debug/pprof/")
}
conf, err := server.LoadConfig(*config)
if err != nil {
log.Fatal(err)
}
c := server.NewController(conf, *mprofile, *profile, os.Getenv("STATIC"))
err = http.ListenAndServe(*addr, c)
if err != nil {
log.Fatal("unable to start server")
}
}