1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-01-23 11:14:48 +02:00
imgproxy/main.go

36 lines
588 B
Go
Raw Normal View History

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