Add new endpoints to expose system status and software information: - /system/getStatus returns current system status (online/offline) - /system/getSoftwareInfo returns software version and build details Update API documentation to include new endpoints
71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"super-frpc/postLog"
|
|
)
|
|
|
|
func setupRoutes() {
|
|
postLog.Info("Setting up routes...")
|
|
http.HandleFunc("/system/getStatus", GetStatusHandler)
|
|
http.HandleFunc("/system/getSoftwareInfo", GetSoftwareInfoHandler)
|
|
|
|
http.HandleFunc("/register", RegisterHandler)
|
|
http.HandleFunc("/login", LoginHandler)
|
|
http.HandleFunc("/logout", LogoutHandler)
|
|
|
|
http.HandleFunc("/userMgr/create", CreateUserHandler)
|
|
http.HandleFunc("/userMgr/remove", RemoveUserHandler)
|
|
http.HandleFunc("/userMgr/list", ListUserHandler)
|
|
// http.HandleFunc("/userMgr/modify", ModifyUserHandler)
|
|
|
|
http.HandleFunc("/sessionMgr/list", ListActiveSessionsHandler)
|
|
http.HandleFunc("/sessionMgr/remove", RemoveSessionHandler)
|
|
|
|
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/") { // Check if path is at least as long as the base path
|
|
SendErrorResponse(w, http.StatusNotFound, "invalid path")
|
|
return
|
|
}
|
|
|
|
remainingPath := path[len("/frpcAct/instanceMgr/"):] // Get the remaining path after the base path
|
|
|
|
if r.Method == http.MethodGet { // Handle `/list` and `/list/<instanceName>` by GET request
|
|
if remainingPath == "list" {
|
|
ListInstancesHandler(w, r)
|
|
return
|
|
}
|
|
|
|
instanceName := strings.Trim(remainingPath, "/") // Get the instance name from the remaining path
|
|
if instanceName != "" {
|
|
ListInstancesHandler(w, r)
|
|
return
|
|
}
|
|
}
|
|
|
|
if r.Method == http.MethodPost { // Handle `/create`, `/delete`, and `/modify/<field>` by POST request
|
|
if remainingPath == "create" {
|
|
CreateInstanceHandler(w, r)
|
|
return
|
|
}
|
|
|
|
if remainingPath == "delete" {
|
|
DeleteInstanceHandler(w, r)
|
|
return
|
|
}
|
|
|
|
if remainingPath == "modify" { // Handle `/modify` by POST request
|
|
ModifyInstanceHandler(w, r)
|
|
return
|
|
}
|
|
}
|
|
|
|
SendErrorResponse(w, http.StatusNotFound, "endpoint not found") // Send error response if no endpoint is found
|
|
})
|
|
}
|