example-gorilla-rest-api

module
v0.0.0-...-55ee965 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2024 License: Apache-2.0

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

Directories

Path Synopsis
cmd
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
internal
app
Package app for handlers
Package app for handlers
app/api/handler/v1
Package v1 for interface UserRepository
Package v1 for interface UserRepository
app/api/handler/v1/mocks
Package mock_v1 is a generated GoMock package.
Package mock_v1 is a generated GoMock package.
app/api/middleware
Package middleware for run logics before main program logics
Package middleware for run logics before main program logics
app/api/utils
Package utils for custom utilits like as custom validator and etc.
Package utils for custom utilits like as custom validator and etc.
app/service
Package service for behavior & logic
Package service for behavior & logic
config
Package config provides types and functions for parsing config file, environment variables and command-line flags.
Package config provides types and functions for parsing config file, environment variables and command-line flags.
logger
Package logger provides types and functions for make a logger with format and level.
Package logger provides types and functions for make a logger with format and level.
migrations
Package migrations for update migrations
Package migrations for update migrations
storage/postgres
Package pg for postgress database
Package pg for postgress database
storage/sqlite
Package sqlite for sqlite database
Package sqlite for sqlite database
Package models for users
Package models for users

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL