Go playground Web API using Gin, Swaggo, CORS gin's middleware and GORM
Go version 1.14
The idea of this project is to provide all the apis that exists in my other repositories NetCore.Playground.Api and node-playground-api
What we get from this:
- We practice different approaches in Go
- We can compare Go implementations with the same ones written in .NetCore and Node.js
- We have three versions of the same Web Api written in different languages, that can be switched from a UI having the exact same results
I have created three UI projects to consume the APIs created here, you can use either of the following repositories:
- Install Go
- VS Code Extension for Go
- MySQL instance in your system
- This is optional and used only for implemented CRUD operations using GORM
- If you are not interested in this part, you can avoid the installtion of MySQL and just change the flag named useMysqlDb in main.go file
- Download Gin framework:
go get github.com/gin-gonic/gin
- Download Swag for Go:
go get -u github.com/swaggo/swag/cmd/swag
- Download gin-swagger by using:
$ go get -u github.com/swaggo/gin-swagger
$ go get -u github.com/swaggo/files
- Download MySQL driver for Go:
go get github.com/go-sql-driver/mysql
- Download GORM:
go get github.com/jinzhu/gorm
- Go to the file database/Database.go and update DBName, Host, Port, User and Password according to your local environment configuration
- From the terminal:
go run playground
- Once it's running, go to a browser
- Hit the following url http://localhost:8080/swagger/index.html
If you change or add new apis:
- Make sure they have the proper General API annotations
- Run the Swaggo command to regenerate the documentation:
swag init
- That's all 😃