0
Files
joyproxy/cmd/joyproxy/main.go
eleksir 79d9a2f604 Change layout to more go-style-ish, replace some modules
* Deejay files, split them to achieve go-style project layout
* Replace logrus with log/slog module to reduce dependencies
* Replace gopkg.in/ini.v1 with github.com/wlevene/ini to make sure all modules BSD licensed
* Update linter config && fix tons of linter warnings
* Update .gitignore
* Update README.md
2025-11-09 22:32:50 +03:00

38 lines
1.0 KiB
Go

// Package main represents entry point function of application.
package main
import (
"net/http"
"os"
"time"
"joyproxy/internal/joyproxy"
"joyproxy/internal/log"
)
// main application entry point.
func main() {
joyproxy.LoadConf()
log.Init(joyproxy.Cfg.Loglevel, os.Stderr)
http.HandleFunc("/joyproxy/", joyproxy.JoyproxyHandler)
http.HandleFunc("/joyurl", joyproxy.JoyurlHandler)
log.Infof("Starting application on port %v\n", joyproxy.Cfg.Port)
// To prevent slow loris ddos, we have to define custom handler because builtin http.ListenAndServe() have no
// timeout and sits here forever.
server := &http.Server{
Addr: joyproxy.Cfg.Port,
ReadHeaderTimeout: time.Duration(joyproxy.Cfg.Timeout) * time.Second,
ReadTimeout: time.Duration(joyproxy.Cfg.Timeout) * time.Second,
WriteTimeout: time.Duration(joyproxy.Cfg.Timeout) * time.Second,
IdleTimeout: time.Duration(joyproxy.Cfg.Timeout) * time.Second,
}
log.Warn(server.ListenAndServe().Error())
}
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */