Broilerplate - A template project for new Go web backend applications

Broilerplate

A template project for new Go web backend applications.

Can be used as a starting point for quickly prototyping a REST API or fully-fledged server-rendered web application in Go, backend by a relational database and common authentication / authorization. Originating from my work on wakapi.

🚀 Features

  • Data management
    • Easy-to-use ORM to map between Go struct and databases entities
    • Multiple databases supported, including MySQL, Postgres and SQLite
    • Simple schema migrations (+ automatic schema generation)
  • Authentication
    • Cookie-based authentication (using gorilla/securecookie)
    • API key authentication (via header or query param)
  • Configuration
    • YAML configuration
    • Environment variables
  • Mailing
    • HTML templates
    • SMTP integration
    • MailWhale integration
  • User Interface
  • Prometheus metrics exports
  • Swagger API docs
  • Unit Testing
  • Docker support

Currently not included

  • Multi-tenancy
  • Advanced authorization mechanisms / RBAC
  • API testing (see wakapi/testing, though)

🧂 Ingredients

🏃‍♀️ Run

Prerequisites

  • Go >= 1.16
  • Node.js >= 14 LTS
  • gcc (to compile go-sqlite3)
    • Fedora / RHEL: dnf install @development-tools
    • Ubuntu / Debian: apt install build-essential
    • Windows: See here

Compile & Run

# Fetch node modules
$ yarn

# Build web assets
$ yarn build:all:compress

# Build the executable
$ go build -o broilerplate

# Adapt config to your needs
$ cp config.default.yml config.yml
$ vi config.yml

# Run it
$ ./broilerplate

🔧 Configuration Options

You can specify configuration options either via a config file (default: config.yml, customizable through the -c argument) or via environment variables. Here is an overview of all options.

YAML Key / Env. Variable Default Description
env /
ENVIRONMENT
dev Whether to use development- or production settings
app.avatar_url_template (see config.default.yml) URL template for external user avatar images (e.g. from Dicebear or Gravatar)
server.port /
BROILERPLATE_PORT
3000 Port to listen on
server.listen_ipv4 /
BROILERPLATE_LISTEN_IPV4
127.0.0.1 IPv4 network address to listen on (leave blank to disable IPv4)
server.listen_ipv6 /
BROILERPLATE_LISTEN_IPV6
::1 IPv6 network address to listen on (leave blank to disable IPv6)
server.listen_socket /
BROILERPLATE_LISTEN_SOCKET
- UNIX socket to listen on (leave blank to disable UNIX socket)
server.timeout_sec /
BROILERPLATE_TIMEOUT_SEC
30 Request timeout in seconds
server.tls_cert_path /
BROILERPLATE_TLS_CERT_PATH
- Path of SSL server certificate (leave blank to not use HTTPS)
server.tls_key_path /
BROILERPLATE_TLS_KEY_PATH
- Path of SSL server private key (leave blank to not use HTTPS)
server.base_path /
BROILERPLATE_BASE_PATH
/ Web base path (change when running behind a proxy under a sub-path)
security.password_salt /
BROILERPLATE_PASSWORD_SALT
- Pepper to use for password hashing
security.insecure_cookies /
BROILERPLATE_INSECURE_COOKIES
false Whether or not to allow cookies over HTTP
security.cookie_max_age /
BROILERPLATE_COOKIE_MAX_AGE
172800 Lifetime of authentication cookies in seconds or 0 to use Session cookies
security.allow_signup /
BROILERPLATE_ALLOW_SIGNUP
true Whether to enable user registration
security.expose_metrics /
BROILERPLATE_EXPOSE_METRICS
false Whether to expose Prometheus metrics under /api/metrics
db.host /
BROILERPLATE_DB_HOST
- Database host
db.port /
BROILERPLATE_DB_PORT
- Database port
db.user /
BROILERPLATE_DB_USER
- Database user
db.password /
BROILERPLATE_DB_PASSWORD
- Database password
db.name /
BROILERPLATE_DB_NAME
app_db.db Database name
db.dialect /
BROILERPLATE_DB_TYPE
sqlite3 Database type (one of sqlite3, mysql, postgres, cockroach)
db.charset /
BROILERPLATE_DB_CHARSET
utf8mb4 Database connection charset (for MySQL only)
db.max_conn /
BROILERPLATE_DB_MAX_CONNECTIONS
2 Maximum number of database connections
db.ssl /
BROILERPLATE_DB_SSL
false Whether to use TLS encryption for database connection (Postgres and CockroachDB only)
db.automgirate_fail_silently /
BROILERPLATE_DB_AUTOMIGRATE_FAIL_SILENTLY
false Whether to ignore schema auto-migration failures when starting up
mail.enabled /
BROILERPLATE_MAIL_ENABLED
true Whether to allow BROILERPLATE to send e-mail (e.g. for password resets)
mail.sender /
BROILERPLATE_MAIL_SENDER
[email protected] Default sender address for outgoing mails (ignored for MailWhale)
mail.provider /
BROILERPLATE_MAIL_PROVIDER
smtp Implementation to use for sending mails (one of [smtp, mailwhale])
mail.smtp.* /
BROILERPLATE_MAIL_SMTP_*
- Various options to configure SMTP. See default config for details
mail.mailwhale.* /
BROILERPLATE_MAIL_MAILWHALE_*
- Various options to configure MailWhale sending service. See default config for details

👏 Support

Coding in open source is my passion and I would love to do it on a full-time basis and make a living from it one day. So if you like this project, please consider supporting it 🙂 . You can donate either through buying me a coffee or becoming a GitHub sponsor. Every little donation is highly appreciated and boosts my motivation to keep improving!

📓 License

MIT

Owner
Ferdinand Mütsch
💪 Never stop learning!
Ferdinand Mütsch
Similar Resources

Extract structured data from web sites. Web sites scraping.

Extract structured data from web sites. Web sites scraping.

Dataflow kit Dataflow kit ("DFK") is a Web Scraping framework for Gophers. It extracts data from web pages, following the specified CSS Selectors. You

Jan 7, 2023

記帳-PWA-web-app (Bookkeeping-PWA-web-app)

記帳-PWA-web-app (Bookkeeping-PWA-web-app)

GoKeep (bookkeeping web app) 記帳-PWA-web-app (Bookkeeping-PWA-web-app) demo link : https://bookkepping.herokuapp.com/ 測試用帳密 : tester002 , tester002 (亦可

Jan 31, 2022

log4jScanner: provides you with the ability to scan internal (only) subnets for vulnerable log4j web servicelog4jScanner: provides you with the ability to scan internal (only) subnets for vulnerable log4j web service

log4jScanner: provides you with the ability to scan internal (only) subnets for vulnerable log4j web servicelog4jScanner: provides you with the ability to scan internal (only) subnets for vulnerable log4j web service

log4jScanner Goals This tool provides you with the ability to scan internal (only) subnets for vulnerable log4j web services. It will attempt to send

Jan 5, 2023

Web terminal - A (unsafe) technical demo to export a shell to web browser

Web terminal - A (unsafe) technical demo to export a shell to web browser

Web Terminal A (unsafe) technical demo to export a shell to web browser. This pr

Dec 27, 2022

Go-web-scaffold - A simple scaffold for building web app quickly

Go-web-scaffold A simple scaffold for building web app quickly. features This sc

Jan 21, 2022

Clean Architecture template for Golang services

Clean Architecture template for Golang services

Go Clean template Clean Architecture template for Golang services Overview The purpose of the template is to show: how to organize a project and preve

Oct 19, 2022

Api-e-commerce - Golang fiber e commerce template

Golang fiber e commerce template Stack Golang v1.17 Fiber v2.24.0 Validation v10

May 7, 2022

Dating-server - Go (Golang) API REST Template/Boilerplate with Gin Framework

go-rest-template Go (Golang) API REST Template/Boilerplate with Gin Framework 1.

Apr 3, 2022

Gorilla is a REST API template for efficient personal development, implemented based on the CleanArchitecture design philosophy.

Gorilla is a REST API template for efficient personal development, implemented based on the CleanArchitecture design philosophy.

The Gorilla Template is a REST API template for efficient personal development, implemented based on the CleanArchitecture design philosophy.

Feb 13, 2022
A web app that displays a new random famous quote every day (UTC timezone) and allows people to like/unlike the quote

Intro A web app that displays a new random famous quote every day (UTC timezone) and allows people to like/unlike the quote. The app display the curre

Dec 8, 2021
This is a template project to help beginners learn, or to help developers develop some interesting small projects
This is a template project to help beginners learn, or to help developers develop some interesting small projects

This is a template project to help beginners learn, or to help developers develop some interesting small projects

Dec 13, 2022
Kratos Project Template for golang

Kratos Project Template Install Kratos go get -u github.com/go-kratos/kratos/cmd/kratos/v2@latest Create a service # Create a template project kratos

Dec 11, 2021
Ares-admin - Kratos Project Template For Golang

Kratos Project Template Install Kratos go get -u github.com/go-kratos/kratos/cmd

Feb 15, 2022
Backend to project Dating App. Written in GO, utilising Gin. MongoDB, AWS S3 and SNS.

Dating API Backend to project Dating App. Written in GO, utilising Gin. MongoDB, AWS S3 and SNS. In order to run simply type "go run ." The API requir

Apr 12, 2022
Short examples of common anti-patterns in Go Web Applications.

Go Web App Anti-Patterns This repository contains short examples of common anti-patterns in Go Web Applications. For complete description, see Common

Dec 31, 2022
staticfiles is an asset manager for a web applications written in Go.

Overview staticfiles is an asset manager for a web applications written in Go. It collects asset files (CSS, JS, images, etc.) from a different locati

Dec 7, 2022
New GF (Go Frame) based back office management system
New GF (Go Frame) based back office management system

GFast-V2 平台简介 基于全新GF(Go Frame)的后台管理系统 前端采用ruoyi-ui 、Vue、Element UI。 阿里云优惠券:点我进入,腾讯云优惠券:点我领取 本项目由奇讯科技团队开发。 特征 高生产率:几分钟即可搭建一个后台管理系统 模块化:单应用多系统的模式,将一个完整的

Dec 31, 2022
Generate a modern Web project with Go and Angular, React or Vue in seconds 🚀
Generate a modern Web project with Go and Angular, React or Vue in seconds 🚀

Goxygen Generate a Web project with Go and Angular, React or Vue. Goxygen aims at saving your time while setting up a new project. It creates a skelet

Jan 5, 2023
This is a web project in golang, where we will try to use multiple concepts
This is a web project in golang, where we will try to use multiple concepts

This is a web project in golang, where we will try to use multiple concepts ##List of all the dependencies we have used in this project Name GoCommand

Feb 10, 2022