go-skeleton

module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: MIT

README ΒΆ

🚒 Going-Merry-Go - Project Skeleton

Welcome aboard the Going-Merry-Go! Inspired by the iconic ship from the anime One Piece, this project is a robust and flexible Go project starter kit. It's designed to help you quickly set up your Go applications with the right structure and essential tools.

πŸ—‚ Project Structure

β”œβ”€β”€ app
β”‚   β”œβ”€β”€ bootstrap      # Contains initialization logic for starting the application
β”‚   └── registry       # Manages dependency injection or service registration
β”œβ”€β”€ bin                # Holds executable files and scripts for running the application
β”œβ”€β”€ cmd
β”‚   β”œβ”€β”€ grpc           # Entry point for starting the gRPC server
β”‚   β”œβ”€β”€ restapi        # Entry point for starting the REST API server
β”‚   β”œβ”€β”€ scheduler      # Entry point for the scheduler service
β”‚   └── worker         # Entry point for worker processes or background jobs
β”œβ”€β”€ config             # Configuration files for the application
β”œβ”€β”€ constant
β”‚   β”œβ”€β”€ ctxkey         # Constants for context keys used across the application
β”‚   β”œβ”€β”€ rediskey       # Redis-related key constants
β”‚   └── restkey        # Constants specific to the REST API
β”œβ”€β”€ database
β”‚   β”œβ”€β”€ migrations     # Database migration scripts to manage schema changes
β”‚   └── seeders        # Seed data for initializing the database with default values
β”œβ”€β”€ docs
β”‚   └── vscode-ext     # Documentation for Visual Studio Code extensions or related setup
β”œβ”€β”€ gen
β”‚   β”œβ”€β”€ grpc
β”‚   β”‚   β”œβ”€β”€ greating   # Auto-generated code for the "greating" gRPC service
β”‚   β”‚   └── health     # Auto-generated code for the health check gRPC service
β”‚   └── pkl
β”‚       β”œβ”€β”€ appconfig  # Generated code for application configuration
β”‚       β”œβ”€β”€ grpcconfig # gRPC configuration details
β”‚       β”œβ”€β”€ httpconfig # HTTP server configuration details
β”‚       β”œβ”€β”€ jwtconfig  # JWT (JSON Web Token) configuration settings
β”‚       β”œβ”€β”€ logconfig
β”‚       β”‚   └── timeformat # Time format settings for logging
β”‚       β”œβ”€β”€ minioconfig # MinIO (object storage) configuration
β”‚       β”œβ”€β”€ mysqlconfig # MySQL database configuration
β”‚       β”œβ”€β”€ natsconfig  # NATS (messaging system) configuration
β”‚       β”œβ”€β”€ otelconfig  # OpenTelemetry configuration for distributed tracing
β”‚       └── redisconfig # Redis database configuration
β”œβ”€β”€ internal
β”‚   β”œβ”€β”€ entity         # Data models and entities used in the application
β”‚   β”œβ”€β”€ grpc
β”‚   β”‚   β”œβ”€β”€ interceptor
β”‚   β”‚   β”‚   β”œβ”€β”€ stream  # Stream interceptors for gRPC requests
β”‚   β”‚   β”‚   β”œβ”€β”€ unary   # Unary interceptors for gRPC requests
β”‚   β”‚   β”‚   └── util    # Utility functions for gRPC interceptors
β”‚   β”‚   └── service    # gRPC service implementations
β”‚   β”œβ”€β”€ http
β”‚   β”‚   β”œβ”€β”€ dto        # Data Transfer Objects for HTTP requests and responses
β”‚   β”‚   β”œβ”€β”€ handler    # Handlers for processing HTTP requests
β”‚   β”‚   β”œβ”€β”€ interceptor # Interceptors for HTTP requests
β”‚   β”‚   β”œβ”€β”€ middleware # Middleware components for HTTP processing
β”‚   β”‚   └── router     # Routing logic for HTTP endpoints
β”‚   β”œβ”€β”€ provider
β”‚   β”‚   β”œβ”€β”€ api        # API providers or service interfaces
β”‚   β”‚   β”œβ”€β”€ attribute  # Attribute-related logic or utilities
β”‚   β”‚   └── impl       # Implementation of the providers
β”‚   β”œβ”€β”€ repo
β”‚   β”‚   β”œβ”€β”€ api        # API for the repository layer
β”‚   β”‚   β”œβ”€β”€ attribute  # Attribute-related logic for the repository layer
β”‚   β”‚   └── impl       # Implementation of repositories
β”‚   β”œβ”€β”€ scheduler      # Scheduler logic for timed or recurring tasks
β”‚   β”œβ”€β”€ service
β”‚   β”‚   β”œβ”€β”€ api        # Service interfaces
β”‚   β”‚   β”œβ”€β”€ attribute  # Attribute-related logic for services
β”‚   β”‚   └── impl       # Implementation of services
β”‚   └── worker
β”‚       β”œβ”€β”€ pub        # Publishing logic for worker processes
β”‚       └── sub        # Subscription logic for worker processes
β”œβ”€β”€ pkg
β”‚   β”œβ”€β”€ xfilter        # Utility for data filtering
β”‚   β”œβ”€β”€ xhttpin        # Helper functions for HTTP input processing
β”‚   β”œβ”€β”€ xhttputil      # Utilities for working with HTTP
β”‚   β”œβ”€β”€ xlazy          # Lazy evaluation utilities
β”‚   β”œβ”€β”€ xlogger        # Logging utilities and helpers
β”‚   β”œβ”€β”€ xresponse      # Utility for handling HTTP responses
β”‚   β”œβ”€β”€ xtracer        # Tools for distributed tracing
β”‚   └── xvalidate      # Input validation utilities
β”œβ”€β”€ pkl                # Placeholder for Pickle files for configuration
β”œβ”€β”€ protos             # Protocol buffer (.proto) files for defining gRPC services
└── storage
    β”œβ”€β”€ assets        # Static assets such as images or other resources
    └── logs          # Log files generated by the application

The project is organized to support different modules such as REST API, gRPC, Pub/Sub, and Cron Jobs, making it easier for you to develop scalable and maintainable applications.

Current Modules
  • APP HTTP/1.1 - REST API βœ…
  • APP HTTP/2 - gRPC βœ…
  • APP Nats.io - Worker Pub/Sub ⏳ (In Progress)
  • APP CronJob - Scheduler Cron Job ⏳ (In Progress)

πŸ“‹ Features

Here's a quick look at what's done and what's still in progress:

Done βœ…
  • πŸ—ƒοΈ Base Structural Directory: Well-organized code structure to get you started quickly.
  • βš™οΈ Setup Basic Generator Configuration: Tools to generate handlers, services, and more.
  • πŸ”§ Registry Dependency, Repository, and Service: Dependency injection setup.
  • 🌐 HTTP Handler and Router Loader: Load and manage routes effortlessly.
  • πŸ›‘οΈ HTTP Interceptor Handler: Middleware to handle requests seamlessly.
  • πŸ“œ DTO Validation: Validate incoming data with ease.
  • πŸ“¦ DB Migrations and Seeders: Database migration and seeding tools.
  • πŸ“„ Logging: Integrated logging for better observability.
  • πŸ“‘ Makefile Runner: Simple command runners for building and testing.
  • 🌍 Open Telemetry Integration: Track and monitor your services.
To Do πŸ“
  • 🐳 Docker Integration: Containerize the application.
  • πŸ“š Open API Generator Docs: Auto-generate API documentation.
  • βš™οΈ CMD Generator: Tool to generate handlers, middleware, routers, repos, and services.
  • πŸ§ͺ Unit Tests: Comprehensive unit testing setup.

πŸ“¦ Installation and Setup

To get started with Going-Merry-Go, follow these steps:

# Clone the repository
git clone https://github.com/Mind2Screen-Dev-Team/going-merry-go.git

# Navigate to the project directory
cd going-merry-go

# Install dependencies and set up the project
make setup

# Run the application
make go-run app=restapi

βš™οΈ Makefile Commands

The Makefile provides a set of commands to help you manage and interact with your Go project efficiently. Below is a list of the available commands:

Setup Commands
  • make setup: Sets up the project by installing necessary tools like protoc-gen-go, protoc-gen-go-grpc, goose, and pkl-gen-go.
Go Commands
  • make go-tidy: Cleans up the go.mod file by removing unnecessary dependencies.
  • make go-run app=<application>: Runs the specified application.
  • make go-build app=<application>: Builds the specified application.
  • make go-gen-proto: Generates Go code from .proto files.
Migration Commands
  • make migrate-up: Migrates the database to the most recent version.
  • make migrate-up-by-one: Migrates the database up by one version.
  • make migrate-down: Rolls back the database version by one.
  • make migrate-status: Displays the migration status of the database.
  • make migrate-create n=<migration_name> t=<sql|go>: Creates a new migration file.
Seeder Commands
  • make seeder-up: Runs the seeders to populate the database.
  • make seeder-down: Rolls back the seeders by one version.
  • make seeder-create n=<seeder_name> t=<sql|go>: Creates a new seeder file.
Utility Commands
  • make print-path: Displays the current PATH environment variable.
  • make migrate-help: Provides help on migration commands.
  • make go-help: Provides help on Go commands.
Examples
# Setup your project workspace
make setup

# Generate Go code from protobuf files
make go-gen-proto

# Run a Go application (example: restapi)
make go-run app=restapi

# Migrate the database to the latest version
make migrate-up

# Create a new migration file
make migrate-create n=create_users_table t=sql

These commands make it easy to manage your Go application, including its dependencies, database migrations, and proto file generation.

πŸ“– Documentation

For detailed documentation and advanced usage, please refer to the Wiki page.

πŸ“œ License

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

🀝 Contributing

We welcome contributions! Feel free to submit issues, fork the repository, and send pull requests.

🌟 Show Your Support

Give a ⭐️ if you like this project!

πŸ“§ Contact

For more information or support, you can reach out to us.

Directories ΒΆ

Path Synopsis
app
cmd
constant
gen
pkl/appconfig
Code generated from Pkl module `AppConfig`.
Code generated from Pkl module `AppConfig`.
pkl/grpcconfig
Code generated from Pkl module `GrpcConfig`.
Code generated from Pkl module `GrpcConfig`.
pkl/httpconfig
Code generated from Pkl module `HttpConfig`.
Code generated from Pkl module `HttpConfig`.
pkl/jwtconfig
Code generated from Pkl module `JwtConfig`.
Code generated from Pkl module `JwtConfig`.
pkl/logconfig
Code generated from Pkl module `LogConfig`.
Code generated from Pkl module `LogConfig`.
pkl/logconfig/timeformat
Code generated from Pkl module `LogConfig`.
Code generated from Pkl module `LogConfig`.
pkl/minioconfig
Code generated from Pkl module `MinioConfig`.
Code generated from Pkl module `MinioConfig`.
pkl/mysqlconfig
Code generated from Pkl module `MySQLConfig`.
Code generated from Pkl module `MySQLConfig`.
pkl/natsconfig
Code generated from Pkl module `NatsConfig`.
Code generated from Pkl module `NatsConfig`.
pkl/otelconfig
Code generated from Pkl module `OtelConfig`.
Code generated from Pkl module `OtelConfig`.
pkl/redisconfig
Code generated from Pkl module `RedisConfig`.
Code generated from Pkl module `RedisConfig`.
internal
pkg

Jump to

Keyboard shortcuts

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