Documentation
¶
Overview ¶
Package monzo is the public entry point for the monzo-go SDK: a complete, production-grade Go client for the Monzo API (https://docs.monzo.com), organised internally with a domain-driven design layering (domain / application / infrastructure).
Construct a Client with New, then call its resource-service fields:
client := monzo.New(
monzo.WithTokens("access-token", "refresh-token"),
monzo.WithClientCredentials("client-id", "client-secret"),
)
accounts, err := client.Accounts.List(ctx, account.ListParams{})
Index ¶
- Constants
- type Client
- type Option
- func WithBaseURL(baseURL string) Option
- func WithClientCredentials(clientID, clientSecret string) Option
- func WithHTTPClient(doer httpclient.Doer) Option
- func WithLogger(logger httpclient.Logger) Option
- func WithRetryPolicy(policy httpclient.RetryPolicy) Option
- func WithTimeout(d time.Duration) Option
- func WithTokenRefreshHook(hook application.TokenRefreshHook) Option
- func WithTokens(accessToken, refreshToken string) Option
- func WithUserAgent(ua string) Option
Constants ¶
const DefaultBaseURL = "https://api.monzo.com"
DefaultBaseURL is the production Monzo API base URL.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
Auth *application.AuthService
Accounts *application.AccountService
Balance *application.BalanceService
Pots *application.PotService
Transactions *application.TransactionService
FeedItems *application.FeedItemService
Attachments *application.AttachmentService
Receipts *application.ReceiptService
Webhooks *application.WebhookService
// contains filtered or unexported fields
}
Client is the SDK entry point. Every resource is exposed as a field backed by an application-layer service, which in turn talks to Monzo through an infrastructure/rest repository.
func (*Client) AccessToken ¶
AccessToken returns the access token currently in use, if any.
type Option ¶
type Option func(*config)
Option configures a Client constructed via New.
func WithBaseURL ¶
WithBaseURL overrides the API base URL. Defaults to DefaultBaseURL. Useful for testing against a mock server.
func WithClientCredentials ¶
WithClientCredentials sets the OAuth2 client id/secret, required for token exchange, manual refresh, and automatic 401 recovery.
func WithHTTPClient ¶
func WithHTTPClient(doer httpclient.Doer) Option
WithHTTPClient overrides the underlying HTTP doer. Defaults to http.DefaultClient. Accepts any httpclient.Doer (typically *http.Client).
func WithLogger ¶
func WithLogger(logger httpclient.Logger) Option
WithLogger sets a structured logger for debug/warn events. Defaults to a no-op logger.
func WithRetryPolicy ¶
func WithRetryPolicy(policy httpclient.RetryPolicy) Option
WithRetryPolicy overrides the retry policy for transient (429/5xx/network) failures on idempotent requests.
func WithTimeout ¶
WithTimeout overrides the per-request timeout. Defaults to 15s.
func WithTokenRefreshHook ¶
func WithTokenRefreshHook(hook application.TokenRefreshHook) Option
WithTokenRefreshHook registers a callback invoked whenever the client automatically refreshes the access token, so you can persist the rotated tokens (Monzo refresh tokens are single-use).
func WithTokens ¶
WithTokens sets the current user's access token and (optionally) refresh token.
func WithUserAgent ¶
WithUserAgent overrides the User-Agent header. Defaults to "monzo-go/<version>".
Directories
¶
| Path | Synopsis |
|---|---|
|
Package application contains use-case orchestration that sits above the domain repositories: client-side validation, pagination helpers, and any logic that doesn't belong in either the domain entities or the transport.
|
Package application contains use-case orchestration that sits above the domain repositories: client-side validation, pagination helpers, and any logic that doesn't belong in either the domain entities or the transport. |
|
domain
|
|
|
account
Package account models the Accounts bounded context.
|
Package account models the Accounts bounded context. |
|
attachment
Package attachment models the Attachments bounded context: hosting and linking images/PDFs against transactions.
|
Package attachment models the Attachments bounded context: hosting and linking images/PDFs against transactions. |
|
auth
Package auth models the OAuth2 authentication bounded context: tokens, the authorization-code flow, and token introspection.
|
Package auth models the OAuth2 authentication bounded context: tokens, the authorization-code flow, and token introspection. |
|
balance
Package balance models the Balance bounded context.
|
Package balance models the Balance bounded context. |
|
feeditem
Package feeditem models the Feed Items bounded context.
|
Package feeditem models the Feed Items bounded context. |
|
pot
Package pot models the Pots bounded context.
|
Package pot models the Pots bounded context. |
|
receipt
Package receipt models the Transaction Receipts bounded context.
|
Package receipt models the Transaction Receipts bounded context. |
|
shared
Package shared contains value objects and error types shared across every bounded context in the monzo-go domain layer.
|
Package shared contains value objects and error types shared across every bounded context in the monzo-go domain layer. |
|
transaction
Package transaction models the Transactions bounded context.
|
Package transaction models the Transactions bounded context. |
|
webhook
Package webhook models the Webhooks bounded context: registering callback URLs and parsing/validating inbound event deliveries.
|
Package webhook models the Webhooks bounded context: registering callback URLs and parsing/validating inbound event deliveries. |
|
examples
|
|
|
oauth
command
Command oauth demonstrates the full OAuth2 authorization-code flow: a tiny HTTP server that sends the user to Monzo, then handles the callback.
|
Command oauth demonstrates the full OAuth2 authorization-code flow: a tiny HTTP server that sends the user to Monzo, then handles the callback. |
|
transactions
command
Command transactions demonstrates listing accounts, reading a balance, and walking every transaction for an account using the pagination.Paginator.
|
Command transactions demonstrates listing accounts, reading a balance, and walking every transaction for an account using the pagination.Paginator. |
|
webhook
command
Command webhook demonstrates registering a webhook and handling inbound transaction.created deliveries.
|
Command webhook demonstrates registering a webhook and handling inbound transaction.created deliveries. |
|
infrastructure
|
|
|
httpclient
Package httpclient provides the low-level HTTP transport shared by every infrastructure/rest repository: auth headers, timeouts, retry-with-backoff on transient failures, and a single automatic re-auth-and-retry on 401s.
|
Package httpclient provides the low-level HTTP transport shared by every infrastructure/rest repository: auth headers, timeouts, retry-with-backoff on transient failures, and a single automatic re-auth-and-retry on 401s. |
|
rest
Package rest implements every domain Repository interface against Monzo's actual HTTP API, using infrastructure/httpclient as the transport.
|
Package rest implements every domain Repository interface against Monzo's actual HTTP API, using infrastructure/httpclient as the transport. |
|
internal
|
|
|
testutil
Package testutil provides shared test doubles used across the test suite.
|
Package testutil provides shared test doubles used across the test suite. |
|
pkg
|
|
|
pagination
Package pagination provides a generic, cursor-based paginator for Monzo list endpoints that are ordered oldest-first and support a `since` cursor plus a page `limit`.
|
Package pagination provides a generic, cursor-based paginator for Monzo list endpoints that are ordered oldest-first and support a `since` cursor plus a page `limit`. |
|
security
Package security provides small, dependency-free cryptographic helpers used by the OAuth2 flow: CSRF state token generation and constant-time comparison.
|
Package security provides small, dependency-free cryptographic helpers used by the OAuth2 flow: CSRF state token generation and constant-time comparison. |