All checks were successful
Deploy to K8s / deploy (push) Successful in 10s
When token is empty, New falls back to transparentClient with the caller-supplied hc. main.go passes nil, so the first Do() call panicked. Default to http.DefaultClient when hc is nil. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
// Package fio fetches Fio bank transactions via the JSON API or the
|
|
// transparent-page HTML scraper, behind a common Client interface.
|
|
package fio
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
// Transaction is one incoming bank payment. Fields absent from the HTML scraper
|
|
// (BankID, Currency, UserID, SenderAccount) are empty strings on that path.
|
|
type Transaction struct {
|
|
Date string
|
|
Amount float64
|
|
Sender string
|
|
Message string
|
|
VS string
|
|
KS string
|
|
SS string
|
|
UserID string // column7; empty on HTML path
|
|
SenderAccount string // column2; empty on HTML path
|
|
BankID string // column22; empty on HTML path
|
|
Currency string // column14; empty on HTML path (assume CZK)
|
|
}
|
|
|
|
// Client fetches transactions for a date window.
|
|
type Client interface {
|
|
FetchTransactions(ctx context.Context, from, to time.Time) ([]Transaction, error)
|
|
}
|
|
|
|
// New returns an apiClient when token is non-empty, otherwise a transparentClient.
|
|
// hc may be nil, in which case http.DefaultClient is used.
|
|
func New(token, accountNum string, hc httpDoer) Client {
|
|
if hc == nil {
|
|
hc = http.DefaultClient
|
|
}
|
|
if token != "" {
|
|
return &apiClient{token: token, hc: hc}
|
|
}
|
|
return &transparentClient{accountNum: accountNum, hc: hc}
|
|
}
|