hr-system-shared

module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2025 License: MIT

README ΒΆ

HR System Shared Libraries

Go Version Go Report Card

Shared Go packages for HR System microservices. This library provides common functionality, utilities, and interfaces used across all HR System services.

πŸ“¦ Packages

Core Packages
  • config - Centralized configuration management with environment variable support
  • logger - Structured logging with request tracing and service context
  • database - Database connection pooling, migrations, and health checks
  • cache - Redis-based caching with consistent interface
  • auth - JWT token management and authentication utilities
HTTP & Middleware
  • middleware - Common HTTP middleware (auth, logging, CORS, rate limiting)
  • httpclient - HTTP client with retry, timeout, and tracing
  • validator - Request validation with custom rules
Infrastructure
  • events - Event bus for inter-service communication
  • health - Health check utilities for services and dependencies
  • metrics - Prometheus metrics collection
  • tracing - OpenTelemetry distributed tracing
Testing
  • testing - Test utilities, fixtures, and database setup
  • mocks - Generated mocks for interfaces

πŸš€ Quick Start

Installation
go get github.com/vltamanec/hr-system-shared
Basic Usage
package main

import (
    "context"
    "log"
    
    "github.com/vltamanec/hr-system-shared/config"
    "github.com/vltamanec/hr-system-shared/logger"
    "github.com/vltamanec/hr-system-shared/database"
)

func main() {
    // Load configuration
    cfg, err := config.Load("config.yaml")
    if err != nil {
        log.Fatal("Failed to load config:", err)
    }
    
    // Initialize logger
    logger := logger.New(cfg.Logging).WithService("my-service")
    
    // Connect to database
    db, err := database.Connect(cfg.Database)
    if err != nil {
        logger.Error("Failed to connect to database", err)
        return
    }
    defer db.Close()
    
    logger.Info("Service started successfully")
}

πŸ“– Documentation

Configuration Example
# config.yaml
server:
  port: 8080
  host: "0.0.0.0"
  read_timeout: 30s
  write_timeout: 30s

database:
  host: localhost
  port: 5432
  user: hr_user
  password: hr_password
  name: hr_db
  max_open_conns: 25
  max_idle_conns: 5

redis:
  addr: localhost:6379
  password: ""
  db: 0
  pool_size: 10

logging:
  level: info
  format: json
  output: stdout

jwt:
  secret: your-super-secret-key
  expiry: 24h
  issuer: hr-system
Environment Variables

All configuration values can be overridden with environment variables:

export HR_SERVER_PORT=8080
export HR_DATABASE_HOST=localhost
export HR_REDIS_ADDR=localhost:6379
export HR_JWT_SECRET=your-secret-key

πŸ§ͺ Testing

Running Tests
# Run all tests
go test ./...

# Run tests with coverage
go test -cover ./...

# Run tests with race detection
go test -race ./...

# Run integration tests (requires Docker)
go test -tags=integration ./...
Test Database Setup
func TestMyService(t *testing.T) {
    // Setup test database with testcontainers
    db := testing.SetupTestDB(t)
    defer db.Close()
    
    // Your test code here
}

πŸ”§ Development

Prerequisites
  • Go 1.23+
  • Docker (for integration tests)
  • Make
Setup
# Clone the repository
git clone https://github.com/vltamanec/hr-system-shared.git
cd hr-system-shared

# Install dependencies
go mod download

# Run tests
make test

# Run linter
make lint

# Generate mocks
make generate
Code Generation
# Generate mocks for interfaces
go generate ./...

# Update dependencies
go mod tidy

πŸ“‹ Contributing

  1. Fork the repository
  2. Create a 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
Code Standards
  • Follow Go Code Review Comments
  • Write tests for all public functions
  • Use meaningful commit messages
  • Update documentation for API changes

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

🀝 Support

For questions and support, please open an issue in the repository.

Directories ΒΆ

Path Synopsis
Package auth provides JWT token management and authentication utilities.
Package auth provides JWT token management and authentication utilities.
Package circuit provides circuit breaker implementation for resilient service calls.
Package circuit provides circuit breaker implementation for resilient service calls.
Package config provides centralized configuration management for HR System services.
Package config provides centralized configuration management for HR System services.
Package database provides database connection pooling, migrations, and health checks.
Package database provides database connection pooling, migrations, and health checks.
Package errors provides enterprise-grade error handling with stack traces, error codes, and categorization.
Package errors provides enterprise-grade error handling with stack traces, error codes, and categorization.
Package examples provides usage examples for HR System Shared Libraries.
Package examples provides usage examples for HR System Shared Libraries.
Package health provides health check utilities for services and dependencies.
Package health provides health check utilities for services and dependencies.
Package logger provides structured logging with request tracing and service context.
Package logger provides structured logging with request tracing and service context.
Package metrics provides enterprise-grade metrics collection using Prometheus.
Package metrics provides enterprise-grade metrics collection using Prometheus.
Package middleware provides common HTTP middleware for HR System services.
Package middleware provides common HTTP middleware for HR System services.
Package testing provides test utilities, fixtures, and database setup for HR System services.
Package testing provides test utilities, fixtures, and database setup for HR System services.

Jump to

Keyboard shortcuts

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