2017-06-20 15:58:55 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2017-09-15 12:29:51 +02:00
|
|
|
"net"
|
2017-06-20 15:58:55 +02:00
|
|
|
"net/http"
|
2017-09-28 15:43:21 +02:00
|
|
|
"runtime/debug"
|
2017-06-20 15:58:55 +02:00
|
|
|
"time"
|
2017-09-15 12:29:51 +02:00
|
|
|
|
|
|
|
"golang.org/x/net/netutil"
|
2017-06-20 15:58:55 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2017-09-28 15:43:21 +02:00
|
|
|
// Force garbage collection
|
|
|
|
go func() {
|
2017-09-28 19:18:01 +02:00
|
|
|
for _ = range time.Tick(10 * time.Second) {
|
2017-09-28 15:43:21 +02:00
|
|
|
debug.FreeOSMemory()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2017-09-15 12:29:51 +02:00
|
|
|
l, err := net.Listen("tcp", conf.Bind)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2017-06-20 15:58:55 +02:00
|
|
|
s := &http.Server{
|
2017-09-27 10:42:49 +02:00
|
|
|
Handler: newHTTPHandler(),
|
2017-06-20 15:58:55 +02:00
|
|
|
ReadTimeout: time.Duration(conf.ReadTimeout) * time.Second,
|
|
|
|
MaxHeaderBytes: 1 << 20,
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("Starting server at %s\n", conf.Bind)
|
|
|
|
|
2017-09-15 12:29:51 +02:00
|
|
|
log.Fatal(s.Serve(netutil.LimitListener(l, conf.MaxClients)))
|
2017-06-20 15:58:55 +02:00
|
|
|
}
|