Skip to content

AtlasBevis/godev

Repository files navigation

🌟 GoDev

GoDev is a comprehensive Go development toolkit that provides essential utilities, integrations, and framework components for building robust applications. It simplifies common development tasks and accelerates project setup with pre-built, production-ready packages.


✨ Features

  • 🗄️ Database: Multi-database support (PostgreSQL, MySQL, SQL Server, Oracle) with query builder
  • 📝 Logging: Structured logging with Zap, file rotation, and HTTP request/response logging
  • 🔄 Redis: Full-featured Redis client with pub/sub, chain operations, and JSON serialization
  • 🐰 RabbitMQ: Message queue integration with publisher/consumer patterns
  • 🔐 Keycloak: Identity and access management integration
  • 🌐 HTTP Server: Gin-based HTTP server with middleware support
  • 📡 REST Client: Type-safe HTTP client with automatic JSON handling
  • Scheduler: Cron job scheduler with timezone support
  • 🏗️ Framework: Application bootstrap with lifecycle management
  • ⚙️ Config: Configuration management with Viper, environment variables, and placeholders
  • 🛠️ Utils: Comprehensive utility functions (crypto, datetime, string, validation, etc.)

📦 Packages

Core Infrastructure

Package Description README
framework Application bootstrap with lifecycle management, service initialization, and graceful shutdown 📖 Read More
config Configuration management with file loading, environment variables, and placeholder expansion 📖 Read More
logger Structured logging with Zap, file rotation, and HTTP logging 📖 Read More

Data & Storage

Package Description README
database Multi-database abstraction with query builder, transactions, and bulk operations 📖 Read More
redis Redis client with chain operations, pub/sub, and JSON serialization 📖 Read More
rabbitmq RabbitMQ integration with publisher/consumer patterns 📖 Read More
migration Database migration utilities 📖 Read More

HTTP & Networking

Package Description README
ginfw/server Gin HTTP server with graceful shutdown and lifecycle hooks 📖 Read More
ginfw/middleware/httplogger HTTP request/response logging middleware 📖 Read More
ginfw/middleware/ratelimit Rate limiting middleware with Allow/Wait modes 📖 Read More
ginfw/middleware/timeout Request timeout middleware 📖 Read More
rest Type-safe REST client with automatic JSON handling 📖 Read More

Services & Integration

Package Description README
keycloak Keycloak identity and access management client 📖 Read More
scheduler Cron job scheduler with timezone support and graceful shutdown 📖 Read More

Utilities

Package Description README
utils Comprehensive utility functions (crypto, datetime, string, validation, file, json, money, random) 📖 Read More
consts Common constants (content types, extensions, patterns) 📖 Read More
types Shared type definitions 📖 Read More

🚀 Quick Start

Installation

go get github.com/BevisDev/godev@latest

Basic Example

package main

import (
	"context"
	"log"
	"time"

	"github.com/BevisDev/godev/database"
	"github.com/BevisDev/godev/framework"
	"github.com/BevisDev/godev/ginfw/server"
	"github.com/BevisDev/godev/logger"
	"github.com/BevisDev/godev/redis"
	"github.com/gin-gonic/gin"
)

func main() {
	ctx := context.Background()

	// Initialize application with framework
	bootstrap := framework.New(
		// Logger
		framework.WithLogger(&logger.Config{
			IsProduction: false,
			IsLocal:      true,
			DirName:      "./logs",
			Filename:     "app.log",
		}),

		// Database
		framework.WithDatabase(&database.Config{
			DBType:   database.Postgres,
			Host:     "localhost",
			Port:     5432,
			DBName:   "mydb",
			Username: "user",
			Password: "password",
			Timeout:  5 * time.Second,
		}),

		// Redis
		framework.WithRedis(&redis.Config{
			Host:    "localhost",
			Port:    6379,
			Timeout: 5 * time.Second,
		}),

		// HTTP Server
		framework.WithServer(&server.Config{
			Port:         8080,
			IsProduction: false,
			Setup: func(r *gin.Engine) {
				r.GET("/health", func(c *gin.Context) {
					c.JSON(200, gin.H{"status": "ok"})
				})
			},
		}),
	)

	// Run application (init, start, graceful shutdown)
	if err := bootstrap.Run(ctx); err != nil {
		log.Fatal(err)
	}
}

Individual Package Usage

Database

import "github.com/BevisDev/godev/database"

db, err := database.New(&database.Config{
	DBType:   database.Postgres,
	Host:     "localhost",
	Port:     5432,
	DBName:   "mydb",
	Username: "user",
	Password: "password",
})
if err != nil {
	log.Fatal(err)
}
defer db.Close()

// Query with builder
users, err := database.Builder[User](db).
	From("users").
	Where("age > ?", 18).
	FindAll(ctx)

Logger

import "github.com/BevisDev/godev/logger"

appLogger, _ := logger.New(&logger.Config{
	IsProduction: true,
	DirName:      "./logs",
	Filename:     "app.log",
	MaxSize:      100,
	MaxBackups:  7,
	MaxAge:      30,
})

appLogger.Info("state", "Application started")

Redis

import "github.com/BevisDev/godev/redis"

cache, err := redis.New(&redis.Config{
	Host:    "localhost",
	Port:    6379,
	Timeout: 5 * time.Second,
})
if err != nil {
	log.Fatal(err)
}
defer cache.Close()

// Chain operations
err = redis.With[User](cache).
	Key("user:1").
	Value(user).
	Expire(10 * time.Second).
	Set(ctx)

REST Client

import "github.com/BevisDev/godev/rest"

client := rest.New(
	rest.WithTimeout(10 * time.Second),
	rest.WithLogger(appLogger),
)

user, err := rest.NewRequest[*UserResponse](client).
	URL("https://api.example.com/users/:id").
	PathParams(map[string]string{"id": "1"}).
	GET(ctx)

📋 Requirements

  • Go: 1.21 or higher
  • Database Drivers (as needed):
    • PostgreSQL: go get github.com/lib/pq
    • MySQL: go get github.com/go-sql-driver/mysql
    • SQL Server: go get github.com/denisenkom/go-mssqldb
    • Oracle: go get github.com/godror/godror@latest

🏗️ Architecture

GoDev follows a modular architecture where each package is independent and can be used standalone or integrated through the framework package:

┌─────────────────────────────────────────┐
│           Framework (Bootstrap)         │
│  - Lifecycle Management                 │
│  - Service Initialization               │
│  - Graceful Shutdown                    │
└─────────────────────────────────────────┘
           │
           ├─── Database ─── Redis ─── RabbitMQ
           │
           ├─── Logger ─── REST Client ─── Scheduler
           │
           └─── HTTP Server (Gin)
                    │
                    ├─── Middleware: Logger, RateLimit, Timeout
                    └─── Routes & Handlers

📚 Documentation

Each package includes comprehensive documentation with examples:


🧪 Testing

All packages include comprehensive unit tests:

# Run all tests
go test ./...

# Run tests for specific package
go test ./database/...
go test ./logger/...

🤝 Contributing

Contributions are welcome! Please follow these steps:

  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

Please ensure:

  • Code follows Go best practices
  • Tests are included for new features
  • Documentation is updated
  • All tests pass

📄 License

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


🙏 Acknowledgments

GoDev is built on top of excellent open-source libraries:

  • Gin - HTTP web framework
  • Zap - Structured logging
  • sqlx - Database extensions
  • go-redis - Redis client
  • Viper - Configuration management
  • Cron - Job scheduling

📞 Support

For questions, issues, or contributions, please open an issue on GitHub.


Made with ❤️ for the Go community

About

This module contains helper utilities and libraries to support developers

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages