A sane and simple Go REST API template.

Overview

Gosane ๐Ÿง˜โ€โ™€๏ธ

License: MIT

A sane and simple Go REST API template. Clone me and edit me to fit your usecase.

What is Gosane?

Gosane is a cloneable API template to get you up and running quickly. It has made a lot of decisions for you, but easily allows you to swap out the things you don't like.

Features

Service Description
Auth ๐Ÿ”‘ Social (FB / Google) as well as email based JWT authentication.
Database ๐Ÿ’ฝ Database support using the amazing https://github.com/ent/ent package.
Email โœ‰๏ธ There's an example AWS SES implementation and an easily extendable interface.
Config ๐Ÿ—ƒ Simple JSON and environment based configuration via https://github.com/sno6/config.
Monitoring ๐Ÿ•ต๏ธ Prometheus handlers for monitoring.
Errors ๐Ÿ”ฆ Automatic sentry error logging via: https://sentry.io
Validation ๐Ÿ‘ฎโ€โ™€๏ธ Validation using an extended version of the https://github.com/go-playground/validator package.
Build / Test ๐Ÿ’ช Automatically build and test your code with built in Github pipelines.
Server ๐Ÿ’ป The underlying server framework is Gin, so you benefit from all the goodness you can find over at: https://github.com/gin-gonic/gin

Structure

Browse the codebase in VS Code here: https://github1s.com/sno6/gosane

Gosane is structured as follows:

Handlers

Each handler (or endpoint) is grouped and encapsulated in its own folder as can be seen here. Firstly, you must define the relative path for the handler group in a file such as this, and then define each endpoint as a separate handler.

Services & Stores

A handler interacts with your business logic through services, which are aptly defined in /service. These services interact with your database entities (using ent) via stores. The flow of information should look something like the following:

Handler <-> Services <-> Stores

A store should never be used directly in a handler, and a service should never be used in a store.

Internal

Anything that isn't considered business logic should live here. Typically you want to structure these as small modules that you could rip out and run isolated from the rest of the project, if you had to. Examples include, email, database, sentry (error management), etc.

Dependencies

Gosane follows a simple dependency injection plan. All dependencies for your API are defined in api/register.go. The server initialises all dependencies and passes them through to the handlers via the Register method.

That's about it, the rest is up to you.

How to use Gosane

1. Clone the project

git clone [email protected]:sno6/gosane.git

2. Run the damn thing

./run.sh

Note that if the above command errors you may need to give the script executive permissions by running: chmod +x ./run.sh

Postman

You can download the exported Postman collection here.

Potential issues

Gosane is complaining about a Sentry DSN, what's that?

In order for Sentry to know where to log errors to it needs a URL. To get one, follow these steps:

  1. Sign up for a free account over at https://sentry.io/welcome
  2. Select Go as the platform.
  3. Copy the Dsn value in the sample code to your .env file.

That's it.

But what if I don't want social OAuth?

Just simply rip out everything for social OAuth. Here's where everything will be:

  1. /api/handler/oauth This whole folder can go.
  2. /api/register.go Remove the reference to the OAuth handler here.
  3. /config/config.go Remove everything to do with OAuth from the config.
  4. /internal/server.go Remove the fb/google configs that are passed to the API as dependencies.

But what if I don't want Sentry?

Similarly, do the following:

  1. /internal/sentry This whole folder can go.
  2. /config/config.go Remove all Sentry related config params.
  3. /api/register.go Remove the reference to Sentry from the dependencies list here.
  4. /internal/server.go Remove the Sentry dependency and deferred handler from here.

For any other problems feel free to create an issue and ping me @sno6.

Future work (to be completed in the near future)

  • ~80-100% testing coverage.
  • Add missing auth related endpoints: "forgot password", "re-send verification email".
  • Handle database migrations.
  • Transaction rollbacks on recovery state.
  • Command line tool to generate new project based on feature requirements.
  • Add an example handler to show pagination & sorting usage.
Issues
Owner
Farley
Open for work! More info at https://farley.ai
Farley
Fast, powerful, yet easy to use template engine for Go. Optimized for speed, zero memory allocations in hot paths. Up to 20x faster than html/template

quicktemplate A fast, powerful, yet easy to use template engine for Go. Inspired by the Mako templates philosophy. Features Extremely fast. Templates

Aliaksandr Valialkin 2.2k Sep 12, 2021
Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application.

goview Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application. Contents Inst

foolin 244 Aug 31, 2021
A demonstrative template for creating reliable Terraform modules

This repository provides a template for creating new Terraform modules. It's intended to demonstrate how one might go about standardizing their modules and subjecting them to integration tests in CI.

Patrick Delaney 3 Sep 1, 2021
Handlebars for golang

raymond Handlebars for golang with the same features as handlebars.js 3.0. The full API documentation is available here: http://godoc.org/github.com/a

Aymerick 440 Aug 27, 2021
A handy, fast and powerful go template engine.

Hero Hero is a handy, fast and powerful go template engine, which pre-compiles the html templates to go code. It has been used in production environme

Lime 1.5k Sep 10, 2021
Templating system for HTML and other text documents - go implementation

FAQ What is Kasia.go? Kasia.go is a Go implementation of the Kasia templating system. Kasia is primarily designed for HTML, but you can use it for any

Michaล‚ Derkacz 72 May 4, 2021
A template to build dynamic web apps quickly using Go, html/template and javascript

gomodest-template A modest template to build dynamic web apps in Go, HTML and sprinkles and spots of javascript. Why ? Build dynamic websites using th

Adnaan Badr 54 Aug 28, 2021
Razor view engine for go

gorazor gorazor is the Go port of the razor view engine originated from asp.net in 2011. In summary, gorazor is: Extremely Fast. Templates are convert

null 787 Sep 13, 2021
comparing the performance of different template engines

goTemplateBenchmark comparing the performance of different template engines full featured template engines Ace Amber Go Handlebars removed - Kasia Mus

null 189 Aug 31, 2021
HTML template engine for Go

Ace - HTML template engine for Go Overview Ace is an HTML template engine for Go. This is inspired by Slim and Jade. This is a refinement of Gold. Exa

Keiji Yoshida 803 Sep 10, 2021
Useful template functions for Go templates.

Sprig: Template functions for Go templates The Go language comes with a built-in template language, but not very many template functions. Sprig is a l

null 2.5k Sep 14, 2021
The worldโ€™s most powerful template engine and Go embeddable interpreter.

The worldโ€™s most powerful template engine and Go embeddable interpreter

Open2b 17 Sep 15, 2021
A sweet velvety templating package

Velvet Velvet is a templating package for Go. It bears a striking resemblance to "handlebars" based templates, there are a few small changes/tweaks, t

Buffalo - The Go Web Eco-System 71 Aug 15, 2021
pongo2 is a Django-syntax like templating-language

Django-syntax like template-engine for Go

Florian Schlachter 2k Sep 14, 2021
A sane and simple Go REST API template.

Gosane ??โ€โ™€๏ธ A sane and simple Go REST API template. Clone me and edit me to fit your usecase. What is Gosane? Gosane is a cloneable API template to g

Farley 71 Sep 4, 2021
โš— The most advanced CLI template on earth! Featuring automatic releases, website generation and a custom CI-System out of the box.

cli-template โœจ โš— A template for beautiful, modern, cross-platform compatible CLI tools written with Go! Getting Started | Wiki This template features

null 10 Aug 28, 2021
"to be defined" - a really simple way to create text templates with placeholders

tbd "to be defined" A really simple way to create text templates with placeholders. This tool is deliberately simple and trivial, no advanced features

Luca Sepe 16 Aug 29, 2021
Simple and fast template engine for Go

fasttemplate Simple and fast template engine for Go. Fasttemplate performs only a single task - it substitutes template placeholders with user-defined

Aliaksandr Valialkin 530 Sep 10, 2021
Simple template suitable for building a webapp backend MVP written in go

A Simple Go Project Template - Suited for Webapp MVPs A simple go project structure setup with all dependencies you need to get your MVP off the groun

El Donaldo 29 Aug 17, 2021