feat: add timezone support with automatic timestamp conversion

Add GetTimezone() API method and WithTimezone() client option.
When enabled, the client lazily fetches the server timezone on
first API call and converts all Timestamp fields in responses
using reflection-based struct walking.
This commit is contained in:
Oliver Jakoubek 2026-02-02 12:34:15 +01:00
commit 1fba43cf90
6 changed files with 339 additions and 3 deletions

View file

@ -47,6 +47,12 @@ func nextRequestID() int64 {
// call sends a JSON-RPC request and parses the response.
// The result parameter should be a pointer to the expected result type.
func (c *Client) call(ctx context.Context, method string, params interface{}, result interface{}) error {
if method != "getTimezone" {
if err := c.ensureTimezone(ctx); err != nil {
return fmt.Errorf("failed to load timezone: %w", err)
}
}
req := JSONRPCRequest{
JSONRPC: "2.0",
Method: method,
@ -138,6 +144,9 @@ func (c *Client) call(ctx context.Context, method string, params interface{}, re
if err := json.Unmarshal(rpcResp.Result, result); err != nil {
return fmt.Errorf("failed to unmarshal result: %w", err)
}
if c.tzEnabled && c.timezone != nil {
c.convertTimestamps(result)
}
}
return nil