CLI: shorter, plainer output
Tables name a journal source by its first two units or identifiers; guard test shows 20 matching lines and addresses (--all for all), no /32; Housecarl connection errors without Go's request URL, said once by guard check; status tells "not running" from "no permission"; bans says when there are none; "1 ban lifted". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
96f551be80
commit
b87cc6fb62
5 files changed
+169
-37
No files matched your search
@@ -27,9 +27,10 @@ const Prefix = "/api/v1"
|
||||
|
||||
// Client talks to one Housecarl.
|
||||
type Client struct {
|
||||
base string
|
||||
token string
|
||||
http *http.Client
|
||||
base string
|
||||
socket string
|
||||
token string
|
||||
http *http.Client
|
||||
}
|
||||
|
||||
// Options say how to reach Housecarl.
|
||||
@@ -72,7 +73,7 @@ func New(o Options) (*Client, error) {
|
||||
}
|
||||
tr.TLSClientConfig = cfg
|
||||
}
|
||||
return &Client{base: base, token: strings.TrimSpace(o.Token), http: &http.Client{Transport: tr, Timeout: timeout}}, nil
|
||||
return &Client{base: base, socket: o.Socket, token: strings.TrimSpace(o.Token), http: &http.Client{Transport: tr, Timeout: timeout}}, nil
|
||||
}
|
||||
|
||||
// Error is an error answer from Housecarl.
|
||||
@@ -89,6 +90,32 @@ func (e *Error) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
// UnreachableError is a request Housecarl never answered: no
|
||||
// connection, a TLS failure, a timeout.
|
||||
type UnreachableError struct {
|
||||
Where string
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e *UnreachableError) Error() string {
|
||||
err := e.Err
|
||||
var ue *url.Error
|
||||
if errors.As(err, &ue) {
|
||||
err = ue.Err // without the method and the URL with its query
|
||||
}
|
||||
return "Housecarl at " + e.Where + " doesn't answer: " + err.Error()
|
||||
}
|
||||
|
||||
func (e *UnreachableError) Unwrap() error { return e.Err }
|
||||
|
||||
// where is where the client reaches Housecarl, for messages.
|
||||
func (c *Client) where() string {
|
||||
if c.socket != "" {
|
||||
return c.socket
|
||||
}
|
||||
return c.base
|
||||
}
|
||||
|
||||
// Refused reports whether Housecarl refused a request for good: asking
|
||||
// again won't help (a bad request, no permission, an address never
|
||||
// banned). Anything else (no answer, a server error) is worth retrying.
|
||||
@@ -123,7 +150,7 @@ func (c *Client) do(ctx context.Context, method, path string, query url.Values,
|
||||
}
|
||||
resp, err := c.http.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
return &UnreachableError{Where: c.where(), Err: err}
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
data, _ := io.ReadAll(io.LimitReader(resp.Body, 16<<20))
|
||||
|
||||
Reference in new issue
Block a user