Files
payments/pkg/client/formance.go
CrimsonandGitHub 4ae387a5d1 test: setup go SDK generation for use in e2e tests and start running CI steps with nix (#377)
* Use formance-sdk-go/v3 to in connector uninstall e2e test

* Compile API docs from openapi spec

* Generate go SDK locally for use in integration tests

* Get rid of unnecessary redirect in e2e tests now that SDK is generated

* Omit generated SDK code from codecoverage checks

* Add flake and envrc for nix

* Run Dirty and Tests CI steps with nix

* Run pre-commit using nix

* Remove duplicated steps from Earthfile

* Fixes for linter

* Add go generate to Justfile pre-commit

* Still run Deploy on ubuntu-latest

* Address coderabbit feedback
2025-03-31 10:30:34 +02:00

143 lines
4.3 KiB
Go

// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
package client
import (
"context"
"github.com/formancehq/payments/pkg/client/internal/hooks"
"github.com/formancehq/payments/pkg/client/internal/utils"
"github.com/formancehq/payments/pkg/client/models/components"
"github.com/formancehq/payments/pkg/client/retry"
"net/http"
"time"
)
// HTTPClient provides an interface for suplying the SDK with a custom HTTP client
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
// String provides a helper function to return a pointer to a string
func String(s string) *string { return &s }
// Bool provides a helper function to return a pointer to a bool
func Bool(b bool) *bool { return &b }
// Int provides a helper function to return a pointer to an int
func Int(i int) *int { return &i }
// Int64 provides a helper function to return a pointer to an int64
func Int64(i int64) *int64 { return &i }
// Float32 provides a helper function to return a pointer to a float32
func Float32(f float32) *float32 { return &f }
// Float64 provides a helper function to return a pointer to a float64
func Float64(f float64) *float64 { return &f }
// Pointer provides a helper function to return a pointer to a type
func Pointer[T any](v T) *T { return &v }
type sdkConfiguration struct {
Client HTTPClient
Security func(context.Context) (interface{}, error)
ServerURL string
Language string
OpenAPIDocVersion string
SDKVersion string
GenVersion string
UserAgent string
RetryConfig *retry.Config
Hooks *hooks.Hooks
Timeout *time.Duration
}
func (c *sdkConfiguration) GetServerDetails() (string, map[string]string) {
return c.ServerURL, map[string]string{}
}
type Formance struct {
Payments *Payments
sdkConfiguration sdkConfiguration
}
type SDKOption func(*Formance)
// WithClient allows the overriding of the default HTTP client used by the SDK
func WithClient(client HTTPClient) SDKOption {
return func(sdk *Formance) {
sdk.sdkConfiguration.Client = client
}
}
// WithSecurity configures the SDK to use the provided security details
func WithSecurity(authorization string) SDKOption {
return func(sdk *Formance) {
security := components.Security{Authorization: &authorization}
sdk.sdkConfiguration.Security = utils.AsSecuritySource(&security)
}
}
// WithSecuritySource configures the SDK to invoke the Security Source function on each method call to determine authentication
func WithSecuritySource(security func(context.Context) (components.Security, error)) SDKOption {
return func(sdk *Formance) {
sdk.sdkConfiguration.Security = func(ctx context.Context) (interface{}, error) {
return security(ctx)
}
}
}
func WithRetryConfig(retryConfig retry.Config) SDKOption {
return func(sdk *Formance) {
sdk.sdkConfiguration.RetryConfig = &retryConfig
}
}
// WithTimeout Optional request timeout applied to each operation
func WithTimeout(timeout time.Duration) SDKOption {
return func(sdk *Formance) {
sdk.sdkConfiguration.Timeout = &timeout
}
}
// New creates a new instance of the SDK with the provided serverURL and options
func New(serverURL string, opts ...SDKOption) *Formance {
sdk := &Formance{
sdkConfiguration: sdkConfiguration{
Language: "go",
OpenAPIDocVersion: "v1",
SDKVersion: "0.0.2",
GenVersion: "2.562.2",
UserAgent: "speakeasy-sdk/go 0.0.2 2.562.2 v1 github.com/formancehq/payments/pkg/client",
ServerURL: serverURL,
Hooks: hooks.New(),
},
}
for _, opt := range opts {
opt(sdk)
}
if sdk.sdkConfiguration.Security == nil {
var envVarSecurity components.Security
if utils.PopulateSecurityFromEnv(&envVarSecurity) {
sdk.sdkConfiguration.Security = utils.AsSecuritySource(envVarSecurity)
}
}
// Use WithClient to override the default client if you would like to customize the timeout
if sdk.sdkConfiguration.Client == nil {
sdk.sdkConfiguration.Client = &http.Client{Timeout: 60 * time.Second}
}
currentServerURL := serverURL
serverURL, sdk.sdkConfiguration.Client = sdk.sdkConfiguration.Hooks.SDKInit(currentServerURL, sdk.sdkConfiguration.Client)
if serverURL != currentServerURL {
sdk.sdkConfiguration.ServerURL = serverURL
}
sdk.Payments = newPayments(sdk.sdkConfiguration)
return sdk
}