gomsvc

module
v0.0.0-...-260af11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2024 License: MIT

README

gomsvc

Opinionated µservices framework for GoLang

Go Report Card GoDoc

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
  1. Install Go (1.18 or later)

    brew install go    # macOS
    
  2. Install Task

    brew install go-task    # macOS
    
  3. 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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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

Directories

Path Synopsis
pkg
asynclib
Package asynclib provides utilities for asynchronous operations in Go, including timeouts, intervals, and worker pools.
Package asynclib provides utilities for asynchronous operations in Go, including timeouts, intervals, and worker pools.
authlib
Package authlib provides OAuth2 token management and JWT validation functionality.
Package authlib provides OAuth2 token management and JWT validation functionality.
certlib
Package certlib provides functionality for generating and managing X.509 certificates and their corresponding private keys.
Package certlib provides functionality for generating and managing X.509 certificates and their corresponding private keys.
cryptolib
Package cryptolib provides cryptographic utilities including AES encryption and decryption.
Package cryptolib provides cryptographic utilities including AES encryption and decryption.
devlib
Package devlib provides development utilities for debugging and logging.
Package devlib provides development utilities for debugging and logging.
enclib
Package enclib provides encoding and decoding utilities for various formats including base64 (standard and URL-safe) and hexadecimal.
Package enclib provides encoding and decoding utilities for various formats including base64 (standard and URL-safe) and hexadecimal.
eventlib
Package eventlib provides a generic event emitter implementation for Go applications.
Package eventlib provides a generic event emitter implementation for Go applications.
gcplib
Package gcplib provides a client for interacting with GCP storage buckets.
Package gcplib provides a client for interacting with GCP storage buckets.
gitlib
Package gitlib provides functionality for Git repository operations such as cloning and checking out specific references (commits, branches, or tags).
Package gitlib provides functionality for Git repository operations such as cloning and checking out specific references (commits, branches, or tags).
jwxlib
Package jwxlib provides JWT (JSON Web Token) and JWE (JSON Web Encryption) functionality using the lestrrat-go/jwx/v2 library.
Package jwxlib provides JWT (JSON Web Token) and JWE (JSON Web Encryption) functionality using the lestrrat-go/jwx/v2 library.
svc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL