Files
backend/router.go
T
NanamiAdmin 182887a66f feat(logging): add detailed logging throughout application components
- Implement logging in router setup, auth handlers, and frpc operations
- Add SoftwareInfo struct for version tracking and logging
- Enhance error messages with more context and logging
- Replace direct error returns with formatted error logging
- Add debug logs for token operations and request validations
2026-02-27 23:44:41 +08:00

65 lines
1.6 KiB
Go

package main
import (
"net/http"
"strings"
"super-frpc/postLog"
)
func setupRoutes() {
postLog.Info("Setting up routes...")
http.HandleFunc("/register", RegisterHandler)
http.HandleFunc("/login", LoginHandler)
http.HandleFunc("/frpcAct/instanceMgr/create", CreateInstanceHandler)
http.HandleFunc("/frpcAct/instanceMgr/list", ListInstancesHandler)
http.HandleFunc("/frpcAct/instanceMgr/", func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
if len(path) < len("/frpcAct/instanceMgr/") {
SendErrorResponse(w, http.StatusNotFound, "invalid path")
return
}
remainingPath := path[len("/frpcAct/instanceMgr/"):]
if r.Method == http.MethodGet {
if remainingPath == "list" {
ListInstancesHandler(w, r)
return
}
instanceName := strings.Trim(remainingPath, "/")
if instanceName != "" {
ListInstancesHandler(w, r)
return
}
}
if r.Method == http.MethodPost {
if remainingPath == "create" {
CreateInstanceHandler(w, r)
return
}
if strings.HasSuffix(remainingPath, "/delete") {
instanceName := strings.TrimSuffix(remainingPath, "/delete")
instanceName = strings.Trim(instanceName, "/")
DeleteInstanceHandler(w, r, instanceName)
return
}
if strings.Contains(remainingPath, "/modify/") {
parts := strings.SplitN(remainingPath, "/modify/", 2)
if len(parts) == 2 {
instanceName := strings.Trim(parts[0], "/")
ModifyInstanceHandler(w, r, instanceName)
return
}
}
}
SendErrorResponse(w, http.StatusNotFound, "endpoint not found")
})
}