Example project with RESTful API on Gorilla mux router
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
To generate documentation we will use swag. How to install:
- Add comments to your API source code. At least fill follow:
// @version
// @title
// @description - Download swag by using:
go install github.com/swaggo/swag/cmd/swag@latest - 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 - Download http-swagger by using:
go get -u github.com/swaggo/http-swaggerAnd import following in your code:import "github.com/swaggo/http-swagger" - Add import to
docsdirectory_ "github.com/mixanemca/example-gorilla-rest-api/docs" - Add to your router - depends on the library you are using (see examples in documentation).
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