Add PostgreSQL, user/squad management, remove private domains from docs

This commit is contained in:
tgvpn
2026-05-21 01:13:23 +03:00
parent d0dc8d5822
commit 5e3229e998
17 changed files with 1171 additions and 58 deletions
+34 -7
View File
@@ -1,6 +1,7 @@
package remnawave
import (
"bytes"
"context"
"encoding/json"
"fmt"
@@ -48,20 +49,38 @@ func (c *Client) countFromEndpoint(ctx context.Context, path, arrayKey string) (
}
func (c *Client) get(ctx context.Context, path string) (*http.Response, []byte, error) {
return c.doRequest(ctx, c.panelURL+path, true)
return c.doRequest(ctx, http.MethodGet, c.panelURL+path, nil, true)
}
func (c *Client) getPublic(ctx context.Context, path string) (*http.Response, []byte, error) {
return c.doRequest(ctx, c.panelURL+path, false)
return c.doRequest(ctx, http.MethodGet, c.panelURL+path, nil, 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)
func (c *Client) post(ctx context.Context, path string, body any) (*http.Response, []byte, error) {
return c.doRequest(ctx, http.MethodPost, c.panelURL+path, body, true)
}
func (c *Client) patch(ctx context.Context, path string, body any) (*http.Response, []byte, error) {
return c.doRequest(ctx, http.MethodPatch, c.panelURL+path, body, true)
}
func (c *Client) doRequest(ctx context.Context, method, url string, body any, withBearer bool) (*http.Response, []byte, error) {
var bodyReader io.Reader
if body != nil {
raw, err := json.Marshal(body)
if err != nil {
return nil, nil, err
}
bodyReader = bytes.NewReader(raw)
}
req, err := http.NewRequestWithContext(ctx, method, url, bodyReader)
if err != nil {
return nil, nil, err
}
req.Header.Set("Accept", "application/json, text/html, */*")
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/json")
if withBearer {
req.Header.Set("Authorization", "Bearer "+c.token)
}
@@ -75,11 +94,19 @@ func (c *Client) doRequest(ctx context.Context, url string, withBearer bool) (*h
}
defer resp.Body.Close()
body, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
respBody, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
if err != nil {
return resp, nil, err
}
return resp, body, nil
return resp, respBody, nil
}
func apiError(status int, body []byte) error {
msg := trimBody(body, 300)
if msg == "" {
return fmt.Errorf("HTTP %d", status)
}
return fmt.Errorf("HTTP %d: %s", status, msg)
}
func parseCount(body []byte, arrayKey string) int {