gomsvc
Opinionated µservices framework for GoLang
Overview
gomsvc
is a modern, opinionated microservices framework for Go that provides a robust foundation for building scalable and maintainable services. It includes utilities for HTTP clients, gRPC services, and common middleware patterns.
Features
-
HTTP Client Library
- Type-safe generic methods
- Comprehensive error handling
- Flexible request configuration
- Automatic retries and timeouts
-
gRPC Support
- Code generation utilities
- Service templates
- Common interceptors
-
Development Tools
- Task-based workflow
- Code generation scripts
- Test coverage reporting
- Linting and formatting
Installation
go get github.com/sandrolain/gomsvc
Quick Start
HTTP Client Example
package main
import (
"context"
"time"
"github.com/sandrolain/gomsvc/pkg/httplib/client"
)
type Response struct {
Message string `json:"message"`
Status int `json:"status"`
}
func main() {
// Initialize request configuration
init := client.Init{
Headers: map[string]string{
"Authorization": "Bearer token",
},
Timeout: 10 * time.Second,
RetryCount: 3,
}
// Make a type-safe GET request
ctx := context.Background()
resp, err := client.GetJSON[Response](ctx, "https://api.example.com/data", init)
if err != nil {
panic(err)
}
// Use the strongly-typed response
fmt.Printf("Status: %d, Message: %s\n", resp.Body.Status, resp.Body.Message)
}
Development
This project uses Task for managing development tasks.
Prerequisites
-
Install Go (1.18 or later)
brew install go # macOS
-
Install Task
brew install go-task # macOS
-
Install project dependencies
task install-deps
Development Commands
Command |
Description |
task test |
Run tests with coverage report |
task gen-grpc |
Generate gRPC code |
task fmt |
Format Go code |
task lint |
Run linters |
task build |
Build the project |
task clean |
Clean build artifacts |
task check |
Run all checks (fmt, lint, test) |
task install-deps |
Install project dependencies |
Project Structure
.
├── cmd/ # Command line tools
├── pkg/ # Public packages
│ ├── httplib/ # HTTP utilities
│ │ ├── client/ # HTTP client package
│ │ └── server/ # HTTP server package
│ └── grpclib/ # gRPC utilities
├── scripts/ # Development scripts
│ ├── test.sh # Test execution
│ └── gen-grpc.sh # gRPC generation
├── Taskfile.yml # Task definitions
└── README.md # This file
Running Tests
The test suite includes unit tests and integration tests:
# Run all tests with coverage
task test
# Run specific package tests
go test ./pkg/httplib/client -v
# Run tests with race detection
go test -race ./...
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
)
- Commit your changes (
git commit -m 'Add amazing feature'
)
- Push to the branch (
git push origin feature/amazing-feature
)
- Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- go-resty - HTTP client library
- Task - Task runner
- buf - Protocol buffer tooling