Skip to content

create-go-app/net_http-go-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

net/http backend template for Create Go App CLI

go versionย go reportย 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

Name Version Type
net/http latest core
gorilla/mux v1.8.0 router
auth0/go-jwt-middleware v1.0.1 middleware
swaggo/http-swagger v1.1.2 middleware
stretchr/testify v1.7.0 tests
golang-jwt/jwt v4.2.0 auth
joho/godotenv v1.4.0 config
jmoiron/sqlx v1.3.4 database
jackc/pgx v4.14.1 database
swaggo/swag v1.7.6 utils
google/uuid v1.3.0 utils
go-playground/validator v10.9.0 utils

๐Ÿ—„ 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.

  • ./app/controllers folder for functional controllers (used in routes)
  • ./app/models folder for describe business models and methods of your project
  • ./app/queries folder for describe queries for models of your project
  • ./app/validators folder for describe validators for models fields

./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.

  • ./pkg/configs folder for configuration functions
  • ./pkg/middleware folder for add middleware (Fiber built-in and yours)
  • ./pkg/routes folder for describe routes of your project
  • ./pkg/utils folder with utility functions (server starter, error checker, etc)

./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.

  • ./platform/database folder with database setup functions (by default, PostgreSQL)
  • ./platform/migrations folder with migration files (used with golang-migrate/migrate tool)

โš™๏ธ 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.