Skip to content

BevisDev/godev

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

175 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

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