/fiber-boilerplate

A starter template for fiber projects

Primary LanguageGoMIT LicenseMIT

Fiber App

This is a project starter for fiber apps

How to use this template

This you can use the temaple button to create a new repo or you can use degit.

$ npx degit https://github.com/Xavier577/fiber-boilerplate.git <project-name>

Running the Server

Tidy dependencies

$ go mod tidy

Starting the server

$ go run main.go

Folder structure

.
├── LICENSE
├── README.md
├── config
│   └── env
│       └── env.go
├── dbconf.yml
├── docs
│   ├── docs.go
│   ├── swagger.json
│   └── swagger.yaml
├── go.mod
├── go.sum
├── main.go
├── migrations
│   └── 20230809154912_dbinit.sql
├── pkg
│   └── number
│       └── number.go
└── users
    ├── handler.go
    └── route.go

Folders and file to take note of

  • docs: generated by swag for api documentation
  • migrations: contains migrations for the postgres (Goose was used to generate and run the migration files but the migrations are handwritten)
  • dbconf.yml: config file for goose

Generate swagger docs with Swag

To generate swagger docs for your APIs with swag, run:

$ swag init -g main.go

Migrations with Goose

Creating Migrations

You can create migrations in either go or sql. SQL is preferred in this project. To generate migrations with in SQL with goose, run:

$ goose -path . create <your-migration-name>

Running up migrations

$ goose -path . up -env <environment> # (check dbconf.yml to see configured environments)

Running down migrations

$ goose -path . down -env <environment> # (check dbconf.yml to see configured environments)