Skip to content

fvmoraes/api-go-gin

Repository files navigation

Basic api in Golang, using Gin and Gorm



Structure and technologies used

What purpose?

The main objective of this project is to learn the Go programming language and explore its packages available in the documentation. Initially, with the creation of a simple API, and later making it more complex, inserting logs, tests and nested endpoint documentation.

Technologies used:

Basic informations:

This project contains 7 API's endpoints, 6 of which are directly linked with a CRUD process to a postgres database.

For basic interaction, you can use Swagger (via browser) or Insomnia (importing the yaml that contains the essential config to init the use).

The postgres database and the pgadmin are already configured, ready for use.

Some test cases were created that can be started with the command go test.

The Project has a mirrored structure in an MVC pattern.



How to use

What do I need to have installed on my computer?

Docker and Docker Compose installed in your machine

Any Linux operating system or Linux subsystem

How to run the project on my computer?

The initial command can be the following:

chmod +x start.sh
./start.sh

After the first run, it may be necessary to run an increment to clean up the database directory for new run's:

sudo rm -Rf postgres-data && ./start.sh

How to access the available features?

The following private addresses are fixed in the Docker-Compose configuration, and give access to project options:

  • http://172.33.0.4:9000/api/v1/ grants access to API and Swagger endpoints.
  • http://172.33.0.3/ grants access to PGAdmin that already has the configuration with the database. Use for login in pgadmin: "[email protected]" and "123456" and for confirmation to access database, the password is "foobar".
  • 172.33.0.2 is the IP address of the database, accessible with the credentials foobar:foobar:foobar on port 5432.

Example of PGAdmin access:

pgadmin/login

Example of use with Swagger:

/api/v1/swagger/index.html

Example of use with Insomnia:

In application options, from the Document or Collection name dropdown menu, select Import/Export. Select an option from the Import Data dropdown menu. Import the file "Insomnia_api-go-gin.yaml". For more information: Insomnia Documentation

Example of "Mock" endpoint access:

/api/v1/foobar/mock

Test generation examples

go test


More API information

List of endpoints

  • GET http://172.33.0.4:9000/api/v1/foobar/mock To shown mock
  • POST http://172.33.0.4:9000/api/v1/foobar/ To create Foobar
  • GET http://172.33.0.4:9000/api/v1/foobar/ To shown all Foobar
  • GET http://172.33.0.4:9000/api/v1/foobar/:id To shown Foobar by ID
  • GET http://172.33.0.4:9000/api/v1/foobar/:reg To shown Foobar by Registration
  • PATCH http://172.33.0.4:9000/api/v1/foobar/:id To edit Foobar by ID
  • DELETE http://172.33.0.4:9000/api/v1/foobar/:id To delete Foobar by ID
  • GET http://172.33.0.4:9000/api/v1/swagger/index.html Swagger


References

This project was created using the following Golang packages



end of README.md

Releases

No releases published

Packages

No packages published