A complete, production-ready Go client library for the Marketstack API has been successfully created at:
public_html/packages/marketstack-go
- Package:
github.com/tigusigalpa/marketstack-go - Author: Igor Sazonov (sovletig@gmail.com)
- License: MIT
- Go Version: 1.21+
- Test Coverage: 75.8%
- Status: ✅ All tests passing
Clientstruct with HTTP client and API key management- Constructor with environment variable support (
MARKETSTACK_API_KEY) - Custom HTTP client support
- Configurable base URL
- Context support for all methods
- Automatic query parameter encoding
-
End-of-Day Data (
eod.go)GetEOD()- Historical EOD data with filtersGetEODLatest()- Latest EOD dataGetEODByDate()- EOD data for specific date
-
Intraday Data (
intraday.go)GetIntraday()- Intraday data with intervalsGetIntradayLatest()- Latest intraday data
-
Tickers (
tickers.go)GetTickers()- Search and list tickersGetTicker()- Get specific ticker details
-
Exchanges (
exchanges.go)GetExchanges()- List all exchangesGetExchange()- Get specific exchange details
-
Currencies (
currencies.go)GetCurrencies()- List supported currencies
-
Timezones (
timezones.go)GetTimezones()- List supported timezones
- Custom
APIErrortype with code and message - Proper error wrapping and context
- Type-safe error checking
- Strongly typed request options with
urltags - Strongly typed responses with
jsontags - Pagination support across all endpoints
- Comprehensive unit tests for all endpoints
- Mock HTTP server using
httptest - Tests for success and error scenarios
- Query parameter validation
- Response deserialization verification
- All 16 tests passing
- README.md - Complete usage guide with examples
- doc.go - Package-level documentation
- CONTRIBUTING.md - Contribution guidelines
- CHANGELOG.md - Version history
- PROJECT_STRUCTURE.md - Architecture overview
- LICENSE - MIT License
- Godoc comments on all public APIs
- examples/basic/main.go - Simple usage example
- examples/advanced/main.go - Advanced features demo
marketstack-go/
├── client.go # Core client (95 lines)
├── errors.go # Error types (19 lines)
├── types.go # Common types (67 lines)
├── doc.go # Package docs (47 lines)
├── eod.go # EOD endpoints (38 lines)
├── intraday.go # Intraday endpoints (32 lines)
├── tickers.go # Tickers endpoints (44 lines)
├── exchanges.go # Exchanges endpoints (56 lines)
├── currencies.go # Currencies endpoint (18 lines)
├── timezones.go # Timezones endpoint (18 lines)
├── *_test.go # Test files (7 files, 400+ lines)
├── go.mod # Module definition
├── go.sum # Dependency checksums
├── README.md # Main documentation (500+ lines)
├── LICENSE # MIT License
├── CONTRIBUTING.md # Contribution guide
├── CHANGELOG.md # Version history
├── PROJECT_STRUCTURE.md # Architecture docs
├── .gitignore # Git ignore rules
└── examples/ # Usage examples
├── basic/main.go
└── advanced/main.go
✅ Formatted: All code formatted with gofmt
✅ Linted: Passes go vet with no issues
✅ Tested: 75.8% test coverage, all tests passing
✅ Documented: Complete godoc comments
✅ Idiomatic: Follows Go best practices
package main
import (
"context"
"fmt"
"log"
"github.com/tigusigalpa/marketstack-go"
)
func main() {
client := marketstack.NewClient("", nil) // Uses MARKETSTACK_API_KEY env var
eodData, err := client.GetEOD(context.Background(), &marketstack.EODOptions{
Symbols: []string{"AAPL", "GOOG"},
DateFrom: "2024-01-01",
DateTo: "2024-01-31",
Limit: 100,
})
if err != nil {
log.Fatalf("Error: %v", err)
}
for _, stock := range eodData.Data {
fmt.Printf("%s: $%.2f on %s\n", stock.Symbol, stock.Close, stock.Date)
}
}github.com/google/go-querystringv1.1.0 - Query parameter encoding- Standard library only (no other external dependencies)
-
Set API Key:
export MARKETSTACK_API_KEY="your-api-key"
-
Install:
go get github.com/tigusigalpa/marketstack-go
-
Import and Use:
import "github.com/tigusigalpa/marketstack-go"
-
Initialize Git repository:
cd public_html/packages/marketstack-go git init git add . git commit -m "Initial release v1.0.0"
-
Create GitHub repository at: https://github.com/tigusigalpa/marketstack-go
-
Push to GitHub:
git remote add origin https://github.com/tigusigalpa/marketstack-go.git git branch -M main git push -u origin main
-
Create release tag:
git tag -a v1.0.0 -m "Release v1.0.0" git push origin v1.0.0
# Run all tests
go test -v ./...
# Run tests with coverage
go test -v -cover ./...
# Generate coverage report
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
# Format code
go fmt ./...
# Lint code
go vet ./...
# Build library
go build ./...
# Run examples (requires API key)
cd examples/basic
go run main.go
cd ../advanced
go run main.goThe Go library mirrors the PHP/Laravel version structure but with Go idioms:
- PHP fluent interface → Go options structs
- Laravel HTTP client → Go net/http
- PHPUnit tests → Go testing package
- Composer → Go modules
- Options Structs: Used instead of fluent interface for better Go idioms
- Context Support: All methods accept context.Context for cancellation
- Error Types: Custom APIError type for API-specific errors
- No Global State: Client is explicitly created and passed
- Testability: httptest for mocking, no external dependencies in tests
- Documentation: Comprehensive godoc comments and examples
✅ All 6 required endpoints implemented ✅ Comprehensive test suite (16 tests, all passing) ✅ 75.8% test coverage ✅ Complete documentation with examples ✅ Idiomatic Go code following best practices ✅ Type-safe API with compile-time checks ✅ Production-ready error handling ✅ Zero external runtime dependencies (except query encoding) ✅ MIT licensed and ready for open source
The library is fully functional, well-tested, documented, and ready for production use.