mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-11 03:06:51 +02:00
api: add system_info endpoint
This commit is contained in:
38
internal/api/v1/system_info.go
Normal file
38
internal/api/v1/system_info.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
agentPkg "github.com/yusing/go-proxy/agent/pkg/agent"
|
||||
U "github.com/yusing/go-proxy/internal/api/v1/utils"
|
||||
config "github.com/yusing/go-proxy/internal/config/types"
|
||||
"github.com/yusing/go-proxy/internal/metrics"
|
||||
)
|
||||
|
||||
func SystemInfo(cfg config.ConfigInstance, w http.ResponseWriter, r *http.Request) {
|
||||
agentName := r.FormValue("agent_name")
|
||||
if agentName == "" {
|
||||
info, err := metrics.GetSystemInfo(r.Context())
|
||||
if err != nil {
|
||||
U.HandleErr(w, r, err)
|
||||
return
|
||||
}
|
||||
U.RespondJSON(w, r, info)
|
||||
} else {
|
||||
agent, ok := cfg.GetAgent(agentName)
|
||||
if !ok {
|
||||
U.HandleErr(w, r, U.ErrInvalidKey("agent_name"), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
respData, status, err := agent.Fetch(r.Context(), agentPkg.EndpointSystemInfo)
|
||||
if err != nil {
|
||||
U.HandleErr(w, r, err)
|
||||
return
|
||||
}
|
||||
if status != http.StatusOK {
|
||||
http.Error(w, string(respData), status)
|
||||
return
|
||||
}
|
||||
U.RespondJSON(w, r, respData)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user