Skip to content

OpenStruct/goeasycli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Bootstrap your next Go project/library easily.

language OS Golang GitHub release date GitHub last commit Golang Contributors License


List of Contents


πŸ”‘ Prerequisites

To use GoEasyCLI, you need to have the following tools installed on your system:

🀸 Quickstart

Install GoEasyCLI with the following command:

Unix-like Systems (Linux, macOS)

sh -c "$(curl -fsSL https://raw.githubusercontent.com/OpenStruct/goeasycli/main/scripts/install.sh)"

Windows

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

πŸͺ„ 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

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 .

😺 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:

Run In Postman

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:

└── πŸ“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.

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:
go env -w CGO_ENABLED=1
  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

TDM-GCC Setup

πŸ“š Creating a Library

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

πŸ—Ί Roadmap

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.

πŸ₯Ί 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:

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 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! 🌟

Star this project

πŸ“œ License

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.