- π Prerequisites
- π€Έ Quickstart
- πͺ Simple and fast project setup
- πΊ API Documentation
- ποΈ Folder Structure
- π Posible Issues
- π Creating a Library
- πΊ Roadmap
- π₯Ί Uninstalling GoEasyCLI
- π Contributing and Community
- βοΈ Show Your Support
- π License
To use GoEasyCLI, you need to have the following tools installed on your system:
Install GoEasyCLI with the following command:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/OpenStruct/goeasycli/main/scripts/install.sh)"
NOTE: Please run Powershell in administrator mode.
powershell -c "irm https://raw.githubusercontent.com/OpenStruct/goeasycli/main/scripts/install.ps1 | iex"
Check available options by running:
goeasycli --help
GoEasyCLI is a command-line interface that automates project creation and setup tasks for Go projects. It streamlines the process of setting up the project structure, installing dependencies, and configuring initial settings, making it easier to start with Go.
goeasycli -p <project_name> -f {gin, fiber, echo}
Replace <project_name>
with your desired project name.
Supported frameworks:
Here's an example:
goeasycli -p fafa_shop_api -f fiber
This command creates a new Go project named fafa_shop_api
using the Fiber web framework.
The next step is to run your new project:
go run .
After running the project, you can explore and interact with the API using Postman. To get started quickly, import our pre-configured API requests by clicking the button below:
Remember to change the port to match your SERVER_PORT. Default is set to 8080
This Postman collection contains all available endpoints with example requests, making it easy to test and understand the API's functionality.
After using GoEasyCLI to create a project, the folder structure will be as follows:
βββ πfafa_shop_api
βββ .env
βββ .gitignore
βββ πconfig
βββ config.go
βββ πcontrollers
βββ health.go
βββ user.go
βββ πdatabase
βββ database.go
βββ go.mod
βββ go.sum
βββ πloggers
βββ sentry.go
βββ zap.go
βββ main.go
βββ πmiddlewares
βββ middlewares.go
βββ πmodels
βββ user.go
βββ πrouters
βββ health.go
βββ routers.go
βββ user.go
βββ πseeds
βββ seed.go
βββ πstructs
βββ structs.go
βββ πtemplates
βββ templates.go
βββ test_database.db
βββ πutils
βββ responses.go
βββ utils.go
This structure provides a solid foundation for your Go project, organized into common directories for configuration, controllers, database handling, logging, middleware, models, routes, templates, seeds, and utilities.
The config
folder contains the configuration settings for the project.
config.go
It initializes the configuration settings, loads the environment variables, and sets the default values for the configuration settings.
You can add more configuration settings to this file as needed.
The controllers
folder contains the controller files for the project. The controller files handle the project's business logic.
health.go
It contains the health check controller, which returns the status of the application.
user.go
It contains a sample user controller, which handles basic CRUD operations for users.
The database
folder contains the project's db configuration and connection settings.
database.go
It sets up the database connection and initializes the database.
It contains the database migration logic to create the required tables. By default, the project uses a SQLite database. You can change the database settings in this file and the .env file to use a different database.
The loggers
folder contains the logger configuration settings for the project. The project uses two loggers: Zap and Sentry.
zap.go
It initializes the Zap logger, which logs messages to the console.
You can customize the logger to log messages to a file or a different output.
sentry.go
It initializes the Sentry logger, which sends error messages to the Sentry service.
You can configure the Sentry logger with your Sentry DSN to send error messages to your Sentry account.
The middlewares
folder contains the middleware settings for the project.
The models
folder contains the model files for the project. The model files define the database schema for the project.
user.go
It contains the user model, which defines the sample user schema.
You can add more model files to define additional database schemas for the project.
The routes
folder contains the route files for the project. The route files define the API routes for the project.
health.go
It contains the health check route, which returns the application status.
routers.go
It initializes the router and registers the API routes for the project. Other route files are registered in this file.
user.go
It contains the sample user routes, which define the API routes for basic CRUD operations on users.
The structs
folder contains the struct files for the project. The struct files define the data structures used in the project.
The seeds
folder contains the seed files for the project. The seed files populate the database with sample data.
seeds.go
It contains the seed logic to populate the database with sample users. You can comment out the seed logic to avoid populating the database with sample data.
The templates
folder contains the template files for the project. The template files define the HTML templates used in the project.
Sometimes, you may need to render HTML templates or send emails with HTML content. In such cases, you can use the template files in this folder.
The utils
folder contains the utility files for the project. The utility files contain helper functions and utility functions used in the project.
responses.go
It contains the response utility functions to send JSON responses to the client. You can customize the response functions to handle different response formats or error messages.
utils.go
It contains the project's utility functions. Utility functions perform common tasks such as string manipulation and data validation.
2024/07/17 15:10:42 C:/WINDOWS/system32/justGo/database/database.go:66
[error] failed to initialize database, got error Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub
failed to connect database
Database connection is nil. cannot run migration
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x28 pc=0x13e4992]
This error is caused by the project using SQLite
as the default database.
To fix this issue, you need to:
- Run this command in your
cmd
orpowershell
:
go env -w CGO_ENABLED=1
- Download a tdm-gcc for your architecture and install it.
During installation, select
TDM-GCC Recommend, All Packages
from the Choose Components Screen. See Screenshot below
GoEasyCLI can also be used to create a Go library. To create a new library, use the following command:
goeasycli -l <library_name> -r repo_url
Replace <library_name>
with your desired library name and repo_url
with the repository's URL.
Here's an example:
goeasycli -l my_awesome_fafa_lib -r https://github.com/heygoeasycli/my_awesome_fafa_lib
This command creates a new Go library named my_awesome_fafa_lib
with the specified repository URL.
The folder structure for the library will be as follows:
βββ πmy_awesome_fafa_lib
βββ .github
βββ goeasycli_tag.yml
βββ config
βββ config.go
βββ database
βββ database.go
βββ email
βββ emails.go
βββ loggers
βββ zap.go
βββ go.mod
βββ go.sum
GoEasyCLI is being built in public. The roadmap is a regularly updated source of truth for the GoEasyCLI community to understand where the product is going in the short, medium, and long term.
GoEasyCLI is managed by Open Struct, a group with the aim of easing the burden of engineers. On our GitHub repo, you can directly influence the roadmap by Creating an issue.
Need to say goodbye? We understand. Here's how to remove GoEasyCLI from your system. Use either of these commands in your terminal:
goeasycli -u
goeasycli uninstall
We would love to develop GoEasyCLI together with our community! The best way to get started is to select any issue from the repo and open a Pull Request!
If you find GoEasyCLI helpful or interesting, please consider giving us a star on GitHub. Your support helps promote the project and lets others know it's worth checking out.
Thank you for being so supportive! π
GoEasyCLI is distributed under the terms of the MIT License. A complete version of the license is available in the LICENSE file in this repository. Any contribution made to this project will be licensed under the MIT License.