run as non root and non host network mode

This commit is contained in:
yusing
2025-01-31 06:32:09 +08:00
parent 357897a0cd
commit b3290e2665
15 changed files with 107 additions and 73 deletions

View File

@@ -2,19 +2,17 @@ package query
import (
"encoding/json"
"fmt"
"io"
"net/http"
v1 "github.com/yusing/go-proxy/internal/api/v1"
U "github.com/yusing/go-proxy/internal/api/v1/utils"
"github.com/yusing/go-proxy/internal/common"
E "github.com/yusing/go-proxy/internal/error"
"github.com/yusing/go-proxy/internal/net/http/middleware"
)
func ReloadServer() E.Error {
resp, err := U.Post(common.APIHTTPURL+"/v1/reload", "", nil)
resp, err := U.FetchAPI(http.MethodPost, "/v1/reload", nil)
if err != nil {
return E.From(err)
}
@@ -32,7 +30,7 @@ func ReloadServer() E.Error {
}
func List[T any](what string) (_ T, outErr E.Error) {
resp, err := U.Get(fmt.Sprintf("%s/v1/list/%s", common.APIHTTPURL, what))
resp, err := U.FetchAPI(http.MethodGet, "/v1/list/"+what, nil)
if err != nil {
outErr = E.From(err)
return

View File

@@ -1,7 +1,9 @@
package utils
import (
"bytes"
"crypto/tls"
"io"
"net"
"net/http"
@@ -26,3 +28,15 @@ var (
Post = httpClient.Post
Head = httpClient.Head
)
func FetchAPI(method, endpoint string, body []byte) (*http.Response, error) {
var bodyReader io.Reader
if body != nil {
bodyReader = bytes.NewReader(body)
}
req, err := http.NewRequest(method, "http://localhost"+common.APIHTTPAddr+endpoint, bodyReader)
if err != nil {
return nil, err
}
return httpClient.Do(req)
}