This commit is contained in:
parent
900b6bd3e7
commit
fa0c7e9373
2 changed files with 9 additions and 0 deletions
2
main.go
2
main.go
|
@ -167,6 +167,8 @@ func requestPerMinute() {
|
||||||
|
|
||||||
func beforeAll(next http.HandlerFunc) http.HandlerFunc {
|
func beforeAll(next http.HandlerFunc) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, req *http.Request) {
|
return func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
defer panicHandler(w)
|
||||||
|
|
||||||
if req.Method != "GET" && req.Method != "HEAD" {
|
if req.Method != "GET" && req.Method != "HEAD" {
|
||||||
io.WriteString(w, "Only GET and HEAD requests are allowed.")
|
io.WriteString(w, "Only GET and HEAD requests are allowed.")
|
||||||
return
|
return
|
||||||
|
|
7
utils.go
7
utils.go
|
@ -55,3 +55,10 @@ func RelativeUrl(in string) (newurl string) {
|
||||||
segment_url.Path = path_prefix + segment_url.Path
|
segment_url.Path = path_prefix + segment_url.Path
|
||||||
return segment_url.RequestURI()
|
return segment_url.RequestURI()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func panicHandler(w http.ResponseWriter) {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
log.Printf("Panic: %v", r)
|
||||||
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue