https://github.com/openstruct/goeasycli
https://github.com/openstruct/goeasycli
api echo-framework fiber-framework gin-framework go golang golang-cli restful-api
Last synced: 12 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/openstruct/goeasycli
- Owner: OpenStruct
- License: mit
- Created: 2024-06-27T20:36:25.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-31T00:40:31.000Z (over 1 year ago)
- Last Synced: 2024-08-01T02:37:10.485Z (over 1 year ago)
- Topics: api, echo-framework, fiber-framework, gin-framework, go, golang, golang-cli, restful-api
- Language: Go
- Homepage: https://openstruct.github.io/goeasycli/
- Size: 7.46 MB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Bootstrap your next Go project/library easily.
[![language][languages-shield]](https://golang.org)
![OS][os-shield]
[![Golang][releases]][repo-url]
![GitHub release date][release-date]
![GitHub last commit][last-commit]
[![Golang][project-download]][downloads-url]
![Contributors][contributors-shield]
[![License][license-shield]][license-url]
[releases]: https://img.shields.io/github/v/release/OpenStruct/goeasycli
[repo-url]: https://github.com/OpenStruct/goeasycli
[GitHub-Version-shield]: https://img.shields.io/github/v/release/OpenStruct/goeasycli
[project-download]: https://img.shields.io/github/downloads/OpenStruct/goeasycli/total
[downloads-url]: https://img.shields.io/github/downloads/OpenStruct/goeasycli/total
[contributors-shield]: https://img.shields.io/github/contributors/OpenStruct/goeasycli?color=7A3EF4
[license-shield]: https://img.shields.io/github/license/OpenStruct/goeasycli?color=9565F6
[codecov-shield]: https://img.shields.io/codecov/c/github/OpenStruct/goeasycli
[codecov-url]: https://codecov.io/gh/OpenStruct/goeasycli
[license-url]: https://opensource.org/licenses/MIT
[languages-shield]: https://img.shields.io/badge/language-go-blue.svg
[os-shield]: https://img.shields.io/badge/OS-linux%2C%20windows%2C%20macOS-0078D4
[release-date]: https://img.shields.io/github/release-date/OpenStruct/goeasycli
[last-commit]: https://img.shields.io/github/last-commit/OpenStruct/goeasycli
---
## List of Contents
- [π Prerequisites](#-prerequisites)
- [π€Έ Quickstart](#-quickstart)
- [πͺ Simple and fast project setup](#-simple-and-fast-project-setup)
- [πΊ API Documentation](#-api-documentation)
- [ποΈ Folder Structure](#-folder-structure)
- [π Posible Issues](#-posible-issues)
- [π Creating a Library](#-creating-a-library)
- [πΊ Roadmap](#-roadmap)
- [π₯Ί Uninstalling GoEasyCLI](#-uninstalling-goeasycli)
- [π Contributing and Community](#-contributing-and-community)
- [βοΈ Show Your Support](#-show-your-support)
- [π License](#-license)
---
## π Prerequisites
To use GoEasyCLI, you **need** to have the following tools installed on your system:
- [Go](https://golang.org/dl/) **1.19 or newer**
- [Git](https://git-scm.com/downloads)
## π€Έ Quickstart
Install GoEasyCLI with the following command:
### Unix-like Systems (Linux, macOS)
```bash
sh -c "$(curl -fsSL https://raw.githubusercontent.com/OpenStruct/goeasycli/main/scripts/install.sh)"
```
### Windows
> **_NOTE:_** Please run Powershell in administrator mode.
```powershell
powershell -c "irm https://raw.githubusercontent.com/OpenStruct/goeasycli/main/scripts/install.ps1 | iex"
```
Check available options by running:
```bash
goeasycli --help
```
## πͺ Simple and fast project setup
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.
### Create a new project with specified options
```bash
goeasycli -p -f {gin, fiber, echo}
```
Replace `` with your desired project name.
**Supported frameworks:**
- [x] [Gin](https://gin-gonic.com)
- [x] [Fiber](https://gofiber.io)
- [x] [Echo](https://echo.labstack.com)
Here's an example:
```bash
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:
```bash
go run .
```
## πΊ API Documentation
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:
[
](https://god.gw.postman.com/run-collection/28835299-b86cba8e-57e5-4e0d-81be-9acbc3fc6fcc?action=collection%2Ffork&source=rip_markdown&collection-url=entityId%3D28835299-b86cba8e-57e5-4e0d-81be-9acbc3fc6fcc%26entityType%3Dcollection%26workspaceId%3D23eb7893-79ca-41ef-96ae-c11a9551cd0c)
> 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.
---
## ποΈ Folder Structure
After using GoEasyCLI to create a project, the folder structure will be as follows:
```shell
βββ π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.
## ποΈ Folder Structure Details
### config
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.
### controllers
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.
### database
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.
### loggers
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.
### middlewares
The `middlewares` folder contains the middleware settings for the project.
### models
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.
### routes
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.
### structs
The `structs` folder contains the struct files for the project. The struct files define the data structures used in the project.
### seeds
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.
### templates
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.
### utils
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.
## π Posible Issues
### Error: `Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub.`
```bash
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:
1. Run this command in your `cmd` or `powershell`:
```bash
go env -w CGO_ENABLED=1
```
2. Download a [tdm-gcc](https://jmeubank.github.io/tdm-gcc) for your architecture and install it.
> During installation, select `TDM-GCC Recommend, All Packages` from the Choose Components Screen. See Screenshot below
>
> 
## π Creating a Library
GoEasyCLI can also be used to create a Go library. To create a new library, use the following command:
```bash
goeasycli -l -r repo_url
```
Replace `` with your desired library name and `repo_url` with the repository's URL.
Here's an example:
```bash
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:
```shell
βββ πmy_awesome_fafa_lib
βββ .github
βββ goeasycli_tag.yml
βββ config
βββ config.go
βββ database
βββ database.go
βββ email
βββ emails.go
βββ loggers
βββ zap.go
βββ go.mod
βββ go.sum
```
## πΊ Roadmap
GoEasyCLI is being built in public. The [roadmap](https://github.com/OpenStruct/goeasycli/issues) 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](https://github.com/OpenStruct), 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](https://github.com/OpenStruct/goeasycli/issues/new/choose).
## π₯Ί Uninstalling GoEasyCLI
Need to say goodbye? We understand. Here's how to remove GoEasyCLI from your system. Use either of these commands in your terminal:
```bash
goeasycli -u
goeasycli uninstall
```
## π Contributing and Community
We would love to develop GoEasyCLI together with our community! The best way to get started is to select any issue from the [repo](https://github.com/OpenStruct/goeasycli/issues) and open a Pull Request!
### Contributors
## βοΈ Show Your Support
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! π
[](https://github.com/OpenStruct/goeasycli/stargazers)
## π License
GoEasyCLI is distributed under the terms of the MIT License.
A complete version of the license is available in the [LICENSE](LICENSE) file in
this repository. Any contribution made to this project will be licensed under the MIT License.