{"id":44670920,"url":"https://github.com/ahmadsaubani/go-rest","last_synced_at":"2026-02-15T02:09:09.607Z","repository":{"id":288395452,"uuid":"965933750","full_name":"ahmadsaubani/go-rest","owner":"ahmadsaubani","description":"This project was created to learn software development, with one key focus on building a boilerplate structure for scalable applications. It serves as a foundation for future projects.","archived":false,"fork":false,"pushed_at":"2025-07-11T13:36:53.000Z","size":10574,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-11T15:49:16.284Z","etag":null,"topics":["go","learn-go","rest-api","restful-api"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahmadsaubani.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-14T06:28:26.000Z","updated_at":"2025-07-11T13:36:56.000Z","dependencies_parsed_at":"2025-07-11T15:18:44.047Z","dependency_job_id":"b3bd70d3-93dd-41c6-b39f-11478abe6be6","html_url":"https://github.com/ahmadsaubani/go-rest","commit_stats":null,"previous_names":["ahmadsaubani/go-rest"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ahmadsaubani/go-rest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmadsaubani%2Fgo-rest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmadsaubani%2Fgo-rest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmadsaubani%2Fgo-rest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmadsaubani%2Fgo-rest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmadsaubani","download_url":"https://codeload.github.com/ahmadsaubani/go-rest/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmadsaubani%2Fgo-rest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29465403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-15T01:01:38.065Z","status":"online","status_checked_at":"2026-02-15T02:00:07.449Z","response_time":118,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","learn-go","rest-api","restful-api"],"created_at":"2026-02-15T02:09:09.144Z","updated_at":"2026-02-15T02:09:09.600Z","avatar_url":"https://github.com/ahmadsaubani.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# 🛠️ Project Overview\n\nThis project is my first step into learning Go (Golang). I created this boilerplate as a starting point to help me build Go projects more easily in the future. It’s designed to be clean, reusable, and flexible so I don’t have to start from scratch every time I create a new project.\n\n🔧 Key Features:\n\n- **Flexible database support**: Easily switch between GORM and native SQL based on `.env` configuration.\n- **Clean architecture**: Organized into controllers, services, repositories, and helpers for better maintainability and testability.\n- **Dynamic filtering \u0026 pagination**: Supports powerful API query filtering (e.g., `?name[like]=john`) and paginated results.\n- **PostgreSQL and MySQL support**: Fully compatible with both databases, including intelligent SQL placeholder formatting.\n- **Migration-friendly**: Automatically generates `CREATE TABLE` statements and database triggers from Go structs.\n- **Supports GORM and native SQL**: Choose your database interaction mode via the `USE_GORM` flag in `.env`.\n- **Auto migration \u0026 auto seeding**: Automatically runs migrations and seeds based on registered entities.\n- **CLI commands via Cobra**: Includes `migrate`, `seed`, and `dropdb` commands for streamlined database management.\n- **Entity auto-registration**: Simply register your models once; they’re used for migration, seeding, and table dropping automatically.\n\n🎯 Purpose \u0026 Vision:\n\nThis boilerplate is more than just a learning exercise—it's a tool I plan to evolve as I grow with Go. My goal is to write clean, maintainable Go code from the beginning. As I build more applications, I’ll continue refining this project to improve structure, developer experience, and performance.\n\n---\n\n## Getting Started\n1. **Clone the repository**:\n```bash\ngit clone https://github.com/ahmadsaubani/go-rest.git\n```\n\n2. **How To Run Development**:\n```sh\nRequirements:\n- go \u003e 1.20.x\n- postgre\n```\n\n```sh\n# Salin file .env default\ncp .env.example .env\n\n# Jalankan aplikasi dengan auto-reload (rekomendasi saat dev)\ngowatch\n\n# Atau manual\ngo run main.go\n\n# Migration \ngo run main.go migrate\n\n# Seeder\ngo run main.go seed\n\n# Drop Table\ngo run main.go dropdb\n\nSemua entitas database didefinisikan dalam file:\n/src/entities/registered.go\n\n\nvar RegisteredEntities = []any{\n\tusers.User{},\n\tauth.AccessToken{},\n\tauth.RefreshToken{},\n\t// Tambahkan entitas lain di sini...\n}\n\n\n```\n\n3. **List Endpoint**:\n```sh\nGET    /api/v1/ping             \nPOST   /api/v1/user/register    \nPOST   /api/v1/user/login       \nGET    /api/v1/user/profile     \nGET    /api/v1/users            \nPOST   /api/v1/token/refresh     \nPOST   /api/v1/user/logout       \n```\n\n4. **Filter Usage**:\n```sh\nExample :\n1. /api/v1/users?email[like]=%john%\u0026age[moreThan]=18\u0026order_by=id,desc\u0026page=1\u0026per_page=10\n```\n\n#### STRUCTURE PROJECT\n```sh\nmyapp/\n├── src/\n│   ├── config/\n│   │  └── database/\n│   │     └── database.go\n│   ├── controllers/\n│   │   └── api/\n│   │       ├── v1/\n│   │       │   ├── auth/\n│   │       │   │   ├── login_controller.go\n│   │       │   │   └── register_controller.go\n│   │       │   └── user/\n│   │       │       └── user_controller.go\n│   ├── entities/\n│   │   ├── auth/\n│   │   │   ├── access_token.go\n│   │   │   └── register_controller.go\n│   │   ├── users/\n│   │   │   └── user.go\n│   ├── helpers/\n│   │   ├── debug.go\n│   │   └── response.go\n│   ├── middleware/\n│   │   └── auth_middleware.go\n│   ├── routes/\n│   │   └── routes.go\n│   ├── seeders/\n│   │   └── user_seeders/\n│   │       └── user_seeder.go\n│   ├── repositories/\n│   │   ├── auth_repositories/\n│   │   │   └── auth_repository_interface.go\n│   │   │   └── auth_repository.go\n│   ├── services/\n│   │   ├── auth_services/\n│   │   │   └── auth_service_interface.go\n│   │   │   └── auth_service.go\n│   ├── utils/\n│   │   └── loggers/\n│   │       └── logger.go\n│   └── storage/\n│       └── logs/\n├── .env\n├── go.sum\n├── go.mod\n└── main.go\n\n\n```\n## Folder Structure\n\n### **1. `src/`**\nThe core source code of the application. This folder contains controllers, routes, entities, helpers, middleware, seeders, services, and utilities.\n- **`config/`**\n  - **`database/`**\n    - **`database.go`**: Handles the configuration and initialization of the database connection. It contains the database connection setup and the DB instance initialization.\n- **`controllers/`**\n  - **`api/`**: Contains the API controllers for handling incoming requests.\n    - **`v1/`**: Version 1 of the API, organizing the controllers into subfolders for specific functionality.\n      - **`auth/`**: Authentication-related controllers.\n        - **`login_controller.go`**: Handles the login logic and authentication requests.\n        - **`register_controller.go`**: Manages user registration logic and new user account creation.\n      - **`user/`**: User-related controllers.\n        - **`user_controller.go`**: Handles user-related functionalities, such as fetching or updating user data.\n\n- **`entities/`**\n  - **`auth/`**: Auth-related entities or models.\n    - **`access_token.go`**: Defines the model and logic for managing access tokens used in the app.\n    - **`refresh_token.go`**: Defines the model and logic for managing access tokens used in the app.\n  - **`users/`**: User-related entities.\n    - **`user.go`**: Defines the user model and handles related database operations.\n\n- **`helpers/`**\n  - **`debug.go`**: Contains utility functions for debugging, such as print-based tools or structured debugging helpers.\n  - **`response.go`**: Provides helper functions to format and send standardized responses (success/failure).\n\n- **`middleware/`**\n  - **`auth_middleware.go`**: Handles authentication checks, including JWT token verification, to protect routes requiring authenticated access.\n\n- **`routes/`**\n  - **`routes.go`**: Manages routing of HTTP requests, maps controllers to routes, and defines the main HTTP request handling logic for the application.\n\n- **`seeders/`**\n  - **`user_seeders/`**\n    - **`user_seeder.go`**: A seeder file to populate the database with initial or test user data, useful for development or testing.\n\n- **`services/`**\n  - **`auth_services/`**\n    - **`auth_service.go`**: Implements the business logic for authentication, including token generation and refreshing tokens.\n\n- **`utils/`**\n  - **`loggers/`**\n    - **`logger.go`**: Implements centralized logging functionality for the application, which might include logging levels, output formats, and log file storage.\n\n- **`storage/`**\n  - **`logs/`**: Stores log files generated during application runtime for debugging or monitoring purposes.\n\n---\n\n### **2. Root Files**\n\n- **`.env`**: Stores environment variables used by the application, such as database credentials, API keys, and the JWT secret.\n- **`go.mod`**: The Go module file that defines the dependencies for the project.\n- **`go.sum`**: Ensures the integrity of the dependencies in `go.mod`.\n- **`main.go`**: The entry point of the application, which initializes the application and starts the HTTP server.\n\n---\n\n## Summary\n\nThe project follows a modular structure where:\n\n- **Controllers** are responsible for handling HTTP requests and routing logic.\n- **Entities** define the data models used throughout the application.\n- **Helpers** provide utility functions for common tasks such as formatting responses.\n- **Middleware** enforces authentication and authorization checks before accessing certain routes.\n- **Seeders** populate the database with initial data for testing or development.\n- **Services** implement the core business logic, particularly for authentication.\n- **Utilities** provide lower-level functionalities like logging.\n- **Storage** holds files such as logs that are generated by the application during runtime.\n\n---","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmadsaubani%2Fgo-rest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmadsaubani%2Fgo-rest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmadsaubani%2Fgo-rest/lists"}