refactor(api): restructure existing routes and remove unused debug endpoints and command line arguments

This commit is contained in:
yusing
2025-05-10 13:12:41 +08:00
parent 26938eb6ed
commit 198ae2cd02
13 changed files with 180 additions and 294 deletions

View File

@@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"github.com/yusing/go-proxy/internal/logging"
@@ -23,6 +22,11 @@ func WriteBody(w http.ResponseWriter, body []byte) {
}
func RespondJSON(w http.ResponseWriter, r *http.Request, data any, code ...int) (canProceed bool) {
if data == nil {
http.NotFound(w, r)
return false
}
if len(code) > 0 {
w.WriteHeader(code[0])
}
@@ -30,8 +34,6 @@ func RespondJSON(w http.ResponseWriter, r *http.Request, data any, code ...int)
var err error
switch data := data.(type) {
case string:
_, err = w.Write([]byte(fmt.Sprintf("%q", data)))
case []byte:
panic("use WriteBody instead")
default: