gorest

command module
v1.6.0-rc.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2022 License: MIT Imports: 6 Imported by: 0

README

gorest | RESTful API Starter kit

CodeQL Go Linter Go Report Card CodeFactor codebeat badge MIT license Contributor Covenant

gorest is a starter kit, written in Golang with Gin framework, for rapid prototyping and developing a RESTful API. The source code is released under the MIT license and is free for any personal or commercial project.

Versioning

1.MAJOR.MINOR.PATCH

1: production-ready

MAJOR: breaking changes

MINOR: new functionality in a backwards compatible manner

PATCH: [optional] backwards compatible bug fixes

Important

Version 1.6.x contains breaking changes!

Note: For version 1.4.5: v1.4.5

Requirement

Go 1.17+

Supported databases

  • MySQL
  • PostgreSQL
  • SQLite3
  • Redis
  • MongoDB

Note: gorest uses GORM as its ORM

Features

  • built on top of Gin
  • use the supported databases without writing any extra configuration files
  • environment variables using GoDotEnv
  • CORS policy
  • basic auth
  • two-factor authentication
  • JWT using golang-jwt/jwt
  • password hashing with Argon2id
  • JSON protection from hijacking
  • simple firewall (whitelist/blacklist IP)
  • email validation (pattern + MX lookup)
  • email verification (sending verification code)
  • forgotten password recovery
  • render HTML templates
  • forward error logs and crash reports to sentry.io
  • super easy to learn and use - lots of example codes

Start building

Tutorials: Wiki

For version 1.6.x, I will publish new tutorials in my free time.

  • convention over configuration
import (
  "github.com/gin-gonic/gin"

  gconfig "github.com/pilinux/gorest/config"
  gcontroller "github.com/pilinux/gorest/controller"
  gdatabase "github.com/pilinux/gorest/database"
  gmiddleware "github.com/pilinux/gorest/lib/middleware"
)
  • install a relational (SQLite3, MySQL or PostgreSQL), Redis, or Mongo database
  • for 2FA, a relational + a redis database is required
  • set up an environment to compile the Go codes (a quick tutorial for any Debian based OS)
  • install git
  • check the Wiki for tutorials

Note: Omit the line setPkFk() in autoMigrate.go file if the driver is not MySQL (check issue: 7)

Note For SQLite3:

  • DBUSER, DBPASS, DBHOST and DBPORT environment variables should be left unchanged.
  • DBNAME must contain the full path and the database file name; i.e,
/user/location/database.db

Contributing

Please see CONTRIBUTING to join this amazing project.

Code of conduct

Please see this document.

License

© Mahir Hasan 2019 - 2022

Released under the MIT license

Documentation

Overview

main function of the application

Directories

Path Synopsis
Package config is responsible for reading all environment variables and set up the base configuration for a functional application
Package config is responsible for reading all environment variables and set up the base configuration for a functional application
Package controller contains all the controllers of the application
Package controller contains all the controllers of the application
Package database handles connections to different types of databases
Package database handles connections to different types of databases
migrate
autoMigrate.go needs to be executed only when it is required to migrate a new relational database schema or to delete an existing database
autoMigrate.go needs to be executed only when it is required to migrate a new relational database schema or to delete an existing database
model
Package model contains all the models required for a functional database management system
Package model contains all the models required for a functional database management system
lib
Package lib provides additional functionalities to the application: - AES encryption-decryption - Argon2id hashing - SHA hashing - Two-factor authentication - Email format validation along with MX lookup
Package lib provides additional functionalities to the application: - AES encryption-decryption - Argon2id hashing - SHA hashing - Two-factor authentication - Email format validation along with MX lookup
middleware
Package middleware contains: - CORS - Application firewall - Pongo2 template engine - JWT - Sentry logger - Two-factor auth validator
Package middleware contains: - CORS - Application firewall - Pongo2 template engine - JWT - Sentry logger - Two-factor auth validator
renderer
Package renderer uses template engine to render and serve HTML pages
Package renderer uses template engine to render and serve HTML pages
Package service contains common functions used by the whole application
Package service contains common functions used by the whole application

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL