Thank you for your interest in contributing to the Marketstack Go Client! This document provides guidelines and instructions for contributing.
- Fork the repository on GitHub
- Clone your fork locally:
git clone https://github.com/YOUR_USERNAME/marketstack-go.git cd marketstack-go - Create a new branch for your feature or bugfix:
git checkout -b feature/your-feature-name
- Go 1.21 or higher
- Git
- A Marketstack API key for testing (get one at marketstack.com)
go mod downloadRun 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 -o coverage.html- Follow standard Go conventions and idioms
- Use
gofmtto format your code:gofmt -w . - Use
go vetto check for common mistakes:go vet ./...
- Add comments to all exported types, functions, and methods
- Keep functions small and focused
- Write descriptive variable and function names
When adding a new feature:
- Write tests first - Follow TDD principles
- Update documentation - Add examples to README.md
- Maintain backwards compatibility - Don't break existing APIs
- Add godoc comments - Document all public APIs
- Follow existing patterns - Look at existing code for consistency
If you're adding support for a new Marketstack API endpoint:
- Create a new file (e.g.,
newfeature.go) - Define the options struct with
urltags:type NewFeatureOptions struct { Param1 string `url:"param1,omitempty"` Param2 int `url:"param2,omitempty"` }
- Define the response struct with
jsontags:type NewFeatureResponse struct { Pagination Pagination `json:"pagination"` Data []NewData `json:"data"` }
- Implement the client method:
func (c *Client) GetNewFeature(ctx context.Context, opts *NewFeatureOptions) (*NewFeatureResponse, error) { var result NewFeatureResponse if err := c.doRequest(ctx, "/newfeature", opts, &result); err != nil { return nil, err } return &result, nil }
- Create comprehensive tests in
newfeature_test.go - Update README.md with usage examples
- Write table-driven tests when appropriate
- Use
httptestto mock API responses - Test both success and error cases
- Verify query parameters are correctly encoded
- Check that responses are properly deserialized
- Test edge cases and boundary conditions
Example test structure:
func TestNewFeature(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Verify request
if r.URL.Path != "/expected/path" {
t.Errorf("unexpected path: %s", r.URL.Path)
}
// Return mock response
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(mockResponse)
}))
defer server.Close()
client := NewClient("test-key", nil)
client.SetBaseURL(server.URL)
result, err := client.NewFeature(context.Background(), opts)
// Assertions
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// ... more assertions
}- Update README.md with new features
- Add godoc comments to all exported symbols
- Include code examples in documentation
- Update CHANGELOG.md (if it exists)
-
Ensure all tests pass:
go test ./... -
Format your code:
gofmt -w . -
Commit your changes with a descriptive message:
git commit -m "Add support for new endpoint" -
Push to your fork:
git push origin feature/your-feature-name
-
Create a Pull Request on GitHub
- Provide a clear description of the changes
- Reference any related issues
- Ensure CI tests pass
- Keep PRs focused on a single feature or fix
- Update documentation as needed
When reporting issues, please include:
- Go version (
go version) - Operating system
- Clear description of the problem
- Steps to reproduce
- Expected vs actual behavior
- Code samples if applicable
- Be respectful and inclusive
- Welcome newcomers
- Focus on constructive feedback
- Help others learn and grow
If you have questions about contributing, feel free to:
- Open an issue on GitHub
- Contact the maintainer at sovletig@gmail.com
Thank you for contributing! 🎉