Skip to content
/ fiber-boilerplate Public template

A fast, scalable and extendable boilerplate for Golang web services

Notifications You must be signed in to change notification settings

hi019/fiber-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fiber-boilerplate

fiber-boilerplate is a boilerplate for Golang web services (rest APIs, templating...) built using Fiber. Its domain-driven design was inspired by Gorsk. Here are some of the boilerplate's out of the box features:

  • Efficient prototyping - Uses Facebook's ORM software, Ent
  • Fast - Fiber benchmarks show that it's the fastest Golang HTTP framework, handling around 35k req/s. That's much more than net/http.
  • Extendable - The boilerplate's domain driven file structure makes organization of large projects easy
  • Easy deployment - A Dockerfile is included for easy deployment wherever Docker is supported

Note

This boilerplate uses Fiber v15, which is currently in beta and will be released to stable on September 15th. Its possible there will be breaking changes between now and that date. In that case, I will continue to update this project.

Usage

After cloning this repository, run go mod download to download the dependencies. This project uses Cobra for its command line interface. You can do go run main.go serve to start the server with the default arguments (port 3000, sqlite) or go run main.go --help to see the available arguments. Air also comes preconfigured, which enables easy reloading on change. To use Air, first see its installation then run air -c air.toml. To customize the command that is ran by Air, open air.toml and change full_bin.

Available routes:

  • POST /signup with body {email: string, password: string}
  • POST /login with body {email: string, password: string}

To use in your own projects, make sure you use your editors Find & Replace feature to replace all refrences to fiber-boilerplate with your project's name. You should also rename the directory. To add additional features like more commands or schemas, see the respective third party documentation like Cobra or Ent

Directory Structure

.
├── air.toml # air configuration  
├── cmd # commands
│   ├── root.go   
│   └── serve.go
├── ent # ent (ORM) configuration. This is auto-generated, you only need to edit files in `schema` 
│   ├── schema
│   │   └── user.go
├── main.go
├── pkg
│   └── api # api modules
│       ├── api.go
│       └── user # user module
│           ├── service.go # user service defintion, includes dependencies, interfaces and an initialization function that returns an instance of the service
│           ├── user.go # the actual implementation of the user service
│           └── web
│               ├── web.go # user module handlers
│               └── web_test.go # handler tests

TODO

  • More unit tests
  • Incorporate Google's Wire for Dependency Injection
  • Add user authentication

About

A fast, scalable and extendable boilerplate for Golang web services

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published