Align Remnawave config with official docs and fix admin health check

This commit is contained in:
tgvpn
2026-05-21 00:59:55 +03:00
parent 7bde0d8a26
commit 7d63603150
7 changed files with 231 additions and 105 deletions
+25 -7
View File
@@ -10,24 +10,32 @@ import (
"time"
)
// Client обращается к Remnawave Panel API:
// - Base: REMNAWAVE_PANEL_URL (например https://panel.example.com)
// - Auth: Authorization: Bearer REMNAWAVE_API_TOKEN
// - Опционально: X-Api-Key: CADDY_AUTH_API_TOKEN
// Документация: https://docs.rw/docs/install/subscription-page/bundled
type Client struct {
baseURL string
panelURL string
token string
caddyToken string
http *http.Client
}
func NewClient(baseURL, apiToken, caddyToken string) *Client {
func NewClient(panelURL, apiToken, caddyAuthToken string) *Client {
return &Client{
baseURL: strings.TrimRight(baseURL, "/"),
panelURL: strings.TrimRight(panelURL, "/"),
token: apiToken,
caddyToken: caddyToken,
caddyToken: caddyAuthToken,
http: &http.Client{
Timeout: 15 * time.Second,
},
}
}
func (c *Client) PanelURL() string { return c.panelURL }
func (c *Client) countFromEndpoint(ctx context.Context, path, arrayKey string) (int, error) {
resp, body, err := c.get(ctx, path)
if err != nil {
@@ -40,13 +48,23 @@ func (c *Client) countFromEndpoint(ctx context.Context, path, arrayKey string) (
}
func (c *Client) get(ctx context.Context, path string) (*http.Response, []byte, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.baseURL+path, nil)
return c.doRequest(ctx, c.panelURL+path, true)
}
func (c *Client) getPublic(ctx context.Context, path string) (*http.Response, []byte, error) {
return c.doRequest(ctx, c.panelURL+path, false)
}
func (c *Client) doRequest(ctx context.Context, url string, withBearer bool) (*http.Response, []byte, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, nil, err
}
req.Header.Set("Authorization", "Bearer "+c.token)
req.Header.Set("Accept", "application/json")
req.Header.Set("Accept", "application/json, text/html, */*")
if withBearer {
req.Header.Set("Authorization", "Bearer "+c.token)
}
if c.caddyToken != "" {
req.Header.Set("X-Api-Key", c.caddyToken)
}