mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-22 09:30:11 +01:00
* feat: idle sleep for proxmox LXCs * refactor: replace deprecated docker api types * chore(api): remove debug task list endpoint * refactor: move servemux to gphttp/servemux; favicon.go to v1/favicon * refactor: introduce Pool interface, move agent_pool to agent module * refactor: simplify api code * feat: introduce debug api * refactor: remove net.URL and net.CIDR types, improved unmarshal handling * chore: update Makefile for debug build tag, update README * chore: add gperr.Unwrap method * feat: relative time and duration formatting * chore: add ROOT_DIR environment variable, refactor * migration: move homepage override and icon cache to $BASE_DIR/data, add migration code * fix: nil dereference on marshalling service health * fix: wait for route deletion * chore: enhance tasks debuggability * feat: stdout access logger and MultiWriter * fix(agent): remove agent properly on verify error * fix(metrics): disk exclusion logic and added corresponding tests * chore: update schema and prettify, fix package.json and Makefile * fix: I/O buffer not being shrunk before putting back to pool * feat: enhanced error handling module * chore: deps upgrade * feat: better value formatting and handling --------- Co-authored-by: yusing <yusing@6uo.me>
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package query
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
|
|
v1 "github.com/yusing/go-proxy/internal/api/v1"
|
|
"github.com/yusing/go-proxy/internal/common"
|
|
"github.com/yusing/go-proxy/internal/gperr"
|
|
"github.com/yusing/go-proxy/internal/net/gphttp"
|
|
"github.com/yusing/go-proxy/internal/net/gphttp/middleware"
|
|
)
|
|
|
|
func ReloadServer() gperr.Error {
|
|
resp, err := gphttp.Post(common.APIHTTPURL+"/v1/reload", "", nil)
|
|
if err != nil {
|
|
return gperr.Wrap(err)
|
|
}
|
|
defer resp.Body.Close()
|
|
if resp.StatusCode != http.StatusOK {
|
|
failure := gperr.Errorf("server reload status %v", resp.StatusCode)
|
|
body, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return failure.With(err)
|
|
}
|
|
reloadErr := string(body)
|
|
return failure.Withf(reloadErr)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func List[T any](what string) (_ T, outErr gperr.Error) {
|
|
resp, err := gphttp.Get(fmt.Sprintf("%s/v1/list/%s", common.APIHTTPURL, what))
|
|
if err != nil {
|
|
outErr = gperr.Wrap(err)
|
|
return
|
|
}
|
|
defer resp.Body.Close()
|
|
if resp.StatusCode != http.StatusOK {
|
|
outErr = gperr.Errorf("list %s: failed, status %v", what, resp.StatusCode)
|
|
return
|
|
}
|
|
var res T
|
|
err = json.NewDecoder(resp.Body).Decode(&res)
|
|
if err != nil {
|
|
outErr = gperr.Wrap(err)
|
|
return
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
func ListRoutes() (map[string]map[string]any, gperr.Error) {
|
|
return List[map[string]map[string]any](v1.ListRoutes)
|
|
}
|
|
|
|
func ListMiddlewareTraces() (middleware.Traces, gperr.Error) {
|
|
return List[middleware.Traces](v1.ListMiddlewareTraces)
|
|
}
|