The Square Go SDK supports sending and receiving extra properties that are not explicitly defined in the SDK types. This is useful when you need to interact with unreleased features, beta functionality, or properties that haven’t been added to the SDK yet.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/square/square-go-sdk/llms.txt
Use this file to discover all available pages before exploring further.
Sending Extra Properties
You can send additional request body properties and query parameters using the request option functions.Extra Query Parameters
Useoption.WithQueryParameters() to add query parameters that aren’t directly supported by the request type.
For example, suppose a new feature was rolled out that allowed you to filter team members by status. You can add the relevant query parameters like this:
The
url.Values type from the standard library net/url package is used to construct the query parameters.Extra Body Properties
Useoption.WithBodyProperties() to add additional fields to the request body:
Receiving Extra Properties
Every response type in the SDK includes theGetExtraProperties() method, which returns a map containing any properties in the JSON response that were not defined in the response struct.
Basic Usage
Access extra properties from any response:Working with Nested Properties
Extra properties can contain nested structures. Use type assertions to work with them:Use Cases
Beta Features
Test unreleased API features during beta periods without waiting for SDK updates.
Backward Compatibility
Access deprecated fields or legacy response properties that may not be in the latest SDK.
Custom Extensions
Work with Square’s custom implementations or partner-specific extensions.
Future-Proofing
Ensure your code can handle new response fields without breaking.
Implementation Details
The extra properties feature is implemented in the SDK’s code generation:- All response structs include an
extraProperties map[string]interface{}field - The JSON unmarshaling process captures unknown fields into this map
- The
GetExtraProperties()method provides safe access to these fields
Best Practices
- Use sparingly: Extra properties should be a temporary solution. Request proper SDK support for frequently used features.
-
Type assertions: Always use type assertions with the ok idiom when accessing extra property values:
- Documentation: Document any extra properties you use in your code comments for future maintainability.
- Testing: Include tests for code that relies on extra properties, as these fields may change without notice.
- Error handling: Be prepared for extra properties to be absent or have different types than expected.
Related Topics
Custom HTTP Client
Learn how to provide custom HTTP clients for advanced use cases
Request Options
Explore all available request options for customizing SDK behavior
