Home

Awesome

net/http backend template for Create Go App CLI

<img src="https://img.shields.io/badge/Go-1.17+-00ADD8?style=for-the-badge&logo=go" alt="go version" /> <a href="https://goreportcard.com/report/github.com/create-go-app/net_http-go-template" target="_blank"><img src="https://img.shields.io/badge/Go_report-A+-success?style=for-the-badge&logo=none" alt="go report" /></a> <img src="https://img.shields.io/badge/license-Apache_2.0-red?style=for-the-badge&logo=none" alt="license" />

Package net provides a portable interface for network I/O, including TCP/IP, UDP, domain name resolution, and Unix domain sockets. Although the package provides access to low-level networking primitives.

Package net/http provides HTTP client and server implementations.

⚡️ Quick start

  1. Create a new project with Fiber:
cgapp create

# Choose a backend framework:
# > net/http
#   fiber
#   chi
  1. Rename .env.example to .env and fill it with your environment values.

  2. Install Docker and the following useful Go tools to your system:

  3. Run project by this command:

make docker.run
  1. Go to API Docs page (Swagger): 127.0.0.1:5000/swagger/index.html

Screenshot

📦 Used packages

NameVersionType
net/httplatestcore
gorilla/muxv1.8.0router
auth0/go-jwt-middlewarev1.0.1middleware
swaggo/http-swaggerv1.1.2middleware
stretchr/testifyv1.7.0tests
golang-jwt/jwtv4.2.0auth
joho/godotenvv1.4.0config
jmoiron/sqlxv1.3.4database
jackc/pgxv4.14.1database
swaggo/swagv1.7.6utils
google/uuidv1.3.0utils
go-playground/validatorv10.9.0utils

🗄 Template structure

./app

Folder with business logic only. This directory doesn't care about what database driver you're using or which caching solution your choose or any third-party things.

./docs

Folder with API Documentation. This directory contains config files for auto-generated API Docs by Swagger.

./pkg

Folder with project-specific functionality. This directory contains all the project-specific code tailored only for your business use case, like configs, middleware, routes or utils.

./platform

Folder with platform-level logic. This directory contains all the platform-level logic that will build up the actual project, like setting up the database or cache server instance and storing migrations.

⚙️ Configuration

# .env

# Server settings:
SERVER_HOST="0.0.0.0"
SERVER_PORT=5000
SERVER_READ_TIMEOUT=60

# JWT settings:
JWT_SECRET_KEY="secret"
JWT_REFRESH_KEY="refresh"

# Database settings:
DB_HOST="cgapp-postgres"
DB_PORT=5432
DB_USER="postgres"
DB_PASSWORD="password"
DB_NAME="postgres"
DB_SSL_MODE="disable"
DB_MAX_CONNECTIONS=100
DB_MAX_IDLE_CONNECTIONS=10
DB_MAX_LIFETIME_CONNECTIONS=2

⚠️ License

Apache 2.0 © Vic Shóstak & True web artisans.