Skip to content

trydirect/go-rest

Repository files navigation

go-rest

RESTful API development template based on GIN framework for development purpose

Stack includes

  • Go 1.13
  • Rest API
  • Swagger
  • GIN 1.5
  • Alpine 3.11

Note

Before installing this project, please, make sure you have installed docker and docker-compose

To install docker execute:

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sh get-docker.sh
$ pip install docker-compose

Installation

Clone this project into your work directory:

$ git clone https://github.com/trydirect/go-rest.git

Then build it via docker-compose:

$ cd go-rest
$ docker-compose up -d
or
$ docker-compose -f docker-compose-debug.yml up

Now, let's check the result

$ curl http://localhost:8080/api/v1/accounts
[{"id":1,"name":"account_1","uuid":"00000000-0000-0000-0000-000000000000"},{"id":2,"name":"account_2","uuid":"00000000-0000-0000-0000-000000000000"},{"id":3,"name":"account_3","uuid":"00000000-0000-0000-0000-000000000000"}]

Go to page http://localhost:8080/swagger/index.html to see generated documentation.

Generating OpenAPI

  1. Add comments to your API source code, See Declarative Comments Format.

  2. Download swag by using:

$ go get -u github.com/swaggo/swag/cmd/swag

Or download a pre-compiled binary from the release page.

  1. Run swag init in the project's root folder. This will parse your comments and generate the required files (docs folder and docs/docs.go).
$ swag init -g app/main.go

Contributing

  1. Fork it (https://github.com/trydirect/go-rest/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Support Development

Donate