This document describes the organization and structure of the Marketstack Go Client library.
marketstack-go/
├── client.go # Core client implementation
├── errors.go # Custom error types
├── types.go # Common data structures
├── doc.go # Package documentation
├── eod.go # End-of-Day data endpoints
├── intraday.go # Intraday data endpoints
├── tickers.go # Tickers endpoints
├── exchanges.go # Exchanges endpoints
├── currencies.go # Currencies endpoint
├── timezones.go # Timezones endpoint
├── client_test.go # Client tests
├── eod_test.go # EOD endpoint tests
├── intraday_test.go # Intraday endpoint tests
├── tickers_test.go # Tickers endpoint tests
├── exchanges_test.go # Exchanges endpoint tests
├── currencies_test.go # Currencies endpoint tests
├── timezones_test.go # Timezones endpoint tests
├── go.mod # Go module definition
├── go.sum # Dependency checksums
├── README.md # Main documentation
├── LICENSE # MIT License
├── CONTRIBUTING.md # Contribution guidelines
├── CHANGELOG.md # Version history
├── .gitignore # Git ignore rules
└── examples/
├── basic/
│ └── main.go # Basic usage example
└── advanced/
└── main.go # Advanced usage example
Clientstruct - Main client typeNewClient()- Constructor functionSetBaseURL()- Base URL configurationdoRequest()- Internal HTTP request handler
APIError- Custom error type for API errorsErrorResponse- API error response wrapper
Common data structures used across endpoints:
Pagination- Pagination metadataEODData- End-of-day stock dataIntradayData- Intraday stock dataTicker- Stock ticker informationStockExchange- Exchange informationCurrency- Currency informationTimezone- Timezone information
Each endpoint is implemented in its own file:
EODOptions- Request parametersEODResponse- Response structureGetEOD()- Get historical EOD dataGetEODLatest()- Get latest EOD dataGetEODByDate()- Get EOD data for specific date
IntradayOptions- Request parametersIntradayResponse- Response structureGetIntraday()- Get intraday dataGetIntradayLatest()- Get latest intraday data
TickersOptions- Request parametersTickersResponse- Response structureTickerResponse- Single ticker responseGetTickers()- Search tickersGetTicker()- Get specific ticker
ExchangesOptions- Request parametersExchangesResponse- Response structureExchangeResponse- Single exchange responseGetExchanges()- List exchangesGetExchange()- Get specific exchange
CurrenciesOptions- Request parametersCurrenciesResponse- Response structureGetCurrencies()- List currencies
TimezonesOptions- Request parametersTimezonesResponse- Response structureGetTimezones()- List timezones
Each endpoint has corresponding test files using httptest to mock API responses:
- Verify correct URL construction
- Test query parameter encoding
- Validate response deserialization
- Check error handling
- Test edge cases
Simple example demonstrating:
- Client initialization
- Getting EOD data
- Getting ticker information
Comprehensive example showing:
- Custom HTTP client configuration
- Context with timeout
- Error handling with type assertions
- Multiple endpoint usage
- Pagination handling
- Data processing
github.com/google/go-querystring- Query parameter encoding- Standard library packages:
context- Request cancellationencoding/json- JSON serializationnet/http- HTTP clientnet/http/httptest- Testing utilities
- Idiomatic Go - Follows Go conventions and best practices
- Type Safety - Strongly typed throughout
- Context Support - All methods accept context.Context
- Error Handling - Custom error types for API errors
- Testability - Comprehensive test coverage using httptest
- Documentation - All public APIs documented with godoc
- Extensibility - Easy to add new endpoints
- Simplicity - Clean, straightforward API design
To add a new endpoint:
-
Create
newfeature.gowith:- Options struct with
urltags - Response struct with
jsontags - Client method(s)
- Options struct with
-
Create
newfeature_test.gowith:- Mock server using httptest
- Test cases for success and error scenarios
- Verify request parameters and response parsing
-
Update documentation:
- Add section to README.md
- Include usage examples
- Update CHANGELOG.md
- Formatted with
gofmt - Linted with
go vet - Documented with godoc comments
- Tested with standard
testingpackage - 75.8% test coverage
- Git repository: https://github.com/tigusigalpa/marketstack-go
- Semantic versioning (SemVer)
- Changelog maintained in CHANGELOG.md