Categorygithub.com/mixanemca/example-gorilla-rest-api
module
0.0.0-20240317163513-55ee9658f042
Repository: https://github.com/mixanemca/example-gorilla-rest-api.git
Documentation: pkg.go.dev

# README

example-gorilla-rest-api

Example project with RESTful API on Gorilla mux router

Help

You can pass the --help flag to see all the flags and description.

Usage of ./example-gorilla-rest-api:
  -c, --config string            path to config file
  -H, --database.host string     database host (default "localhost")
  -N, --database.name string     database name (default "gapi")
  -P, --database.port int        database port (default 5432)
  -U, --database.user string     database user (default "postgres")
  -a, --http.address string      http listening address (default "127.0.0.1:8080")
  -t, --http.timeout.read int    http read timeout (default 5)
  -w, --http.timeout.write int   http write timeout (default 5)
  -f, --log.format log.format    log format (default json)
  -l, --log.level log.level      log level (default info)
pflag: help requested

Swagger

To generate documentation we will use swag. How to install:

  1. Add comments to your API source code. At least fill follow:
// @version 
// @title 
// @description 
  1. Download swag by using: go install github.com/swaggo/swag/cmd/swag@latest
  2. Run the Swag in your Go project root folder which contains main.go file, Swag will parse comments and generate required files(docs folder and docs/doc.go). swag init -g cmd/example-gorilla-rest-api/main.go
  3. Download http-swagger by using: go get -u github.com/swaggo/http-swagger And import following in your code: import "github.com/swaggo/http-swagger"
  4. Add import to docs directory _ "github.com/mixanemca/example-gorilla-rest-api/docs"
  5. Add to your router - depends on the library you are using (see examples in documentation).

Migrations

Install goose one of the commands brew install or goose or go install github.com/pressly/goose/v3/cmd/goose@latest.

Create go file for migrations execute in terminal:

$ mkdir internal/migrations
$ cd  internal/migrations
$ ~/go/bin/goose create add_updated_at go

# Packages

No description provided by the author
Package docs Code generated by swaggo/swag.
Package models for users.