mirror of
https://github.com/Rayzggz/server_torii.git
synced 2025-06-21 22:41:31 +08:00
feat: Use Logx to log
This commit is contained in:
@ -2,13 +2,14 @@ package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"server_torii/internal/action"
|
||||
"server_torii/internal/check"
|
||||
"server_torii/internal/config"
|
||||
"server_torii/internal/dataType"
|
||||
"server_torii/internal/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -37,13 +38,13 @@ func CheckMain(w http.ResponseWriter, userRequestData dataType.UserRequest, rule
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err := w.Write([]byte("OK"))
|
||||
if err != nil {
|
||||
log.Printf("Error write response: %v", err)
|
||||
utils.LogError(userRequestData, fmt.Sprintf("Error writing response: %v", err), "CheckMain")
|
||||
return
|
||||
}
|
||||
} else if bytes.Compare(decision.HTTPCode, []byte("403")) == 0 {
|
||||
tpl, err := template.ParseFiles(cfg.ErrorPage + "/403.html")
|
||||
if err != nil {
|
||||
log.Printf("Error template: %v", err)
|
||||
utils.LogError(userRequestData, fmt.Sprintf("Error parsing template: %v", err), "CheckMain")
|
||||
http.Error(w, "500 - Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@ -60,7 +61,7 @@ func CheckMain(w http.ResponseWriter, userRequestData dataType.UserRequest, rule
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
if err = tpl.Execute(w, data); err != nil {
|
||||
log.Printf("Error template: %v", err)
|
||||
utils.LogError(userRequestData, fmt.Sprintf("Error executing template: %v", err), "CheckMain")
|
||||
http.Error(w, "500 - Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@ -68,7 +69,7 @@ func CheckMain(w http.ResponseWriter, userRequestData dataType.UserRequest, rule
|
||||
} else if bytes.Compare(decision.HTTPCode, []byte("CAPTCHA")) == 0 {
|
||||
tpl, err := template.ParseFiles(cfg.ErrorPage + "/CAPTCHA.html")
|
||||
if err != nil {
|
||||
log.Printf("Error template: %v", err)
|
||||
utils.LogError(userRequestData, fmt.Sprintf("Error parsing template: %v", err), "CheckMain")
|
||||
http.Error(w, "500 - Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@ -76,7 +77,7 @@ func CheckMain(w http.ResponseWriter, userRequestData dataType.UserRequest, rule
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
if err = tpl.Execute(w, nil); err != nil {
|
||||
log.Printf("Error template: %v", err)
|
||||
utils.LogError(userRequestData, fmt.Sprintf("Error executing template: %v", err), "CheckMain")
|
||||
http.Error(w, "500 - Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@ -84,7 +85,7 @@ func CheckMain(w http.ResponseWriter, userRequestData dataType.UserRequest, rule
|
||||
} else if bytes.Compare(decision.HTTPCode, []byte("429")) == 0 {
|
||||
tpl, err := template.ParseFiles(cfg.ErrorPage + "/429.html")
|
||||
if err != nil {
|
||||
log.Printf("Error template: %v", err)
|
||||
utils.LogError(userRequestData, fmt.Sprintf("Error parsing template: %v", err), "CheckMain")
|
||||
http.Error(w, "500 - Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@ -100,14 +101,14 @@ func CheckMain(w http.ResponseWriter, userRequestData dataType.UserRequest, rule
|
||||
w.WriteHeader(http.StatusTooManyRequests)
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
if err = tpl.Execute(w, data); err != nil {
|
||||
log.Printf("Error template: %v", err)
|
||||
utils.LogError(userRequestData, fmt.Sprintf("Error executing template: %v", err), "CheckMain")
|
||||
http.Error(w, "500 - Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
} else {
|
||||
//should never happen
|
||||
log.Printf("Error access in wrong state: %v", decision)
|
||||
utils.LogError(userRequestData, fmt.Sprintf("Error access in wrong state: %v", decision), "CheckMain")
|
||||
http.Error(w, "500 - Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user