Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kfsantos/go-api-car

API developed in golang using swagger to create test environment
https://github.com/kfsantos/go-api-car

api-rest gin-contrib gin-gonic go godotenv golang gorm gorm-orm json postgres

Last synced: 2 days ago
JSON representation

API developed in golang using swagger to create test environment

Awesome Lists containing this project

README

        

# go-api-car

REST API with unit tests and coverage percentage
API developed from a Car CRUD, where unit tests are performed and their percentage of coverage
API developed in golang using swagger to create test environment

# Download Gin Framework

go get github.com/gin-gonic/gin

# Download GORM

go get github.com/jinzhu/gorm

# Download Driver Postgres

go get github.com/jinzhu/gorm/dialects/postgres

# Download GoDotEnv

go get github.com/joho/godotenv

# API

localhost:5000/




  • GET : GET all cars


  • POST : POST create a new car

localhost:5000/:id




  • GET : GET a car


  • PUT : PUT update a car


  • DELETE : DELETE a car

POST Params


{

"name": "Sentra", "brand": "Nissan", "year": "2022/12/12"
}

PUT Params




{
"ID": 1, "name": "Skyline", "brand": "Nissan"
}

# Test

To create test files


gotests -all -w .

Create Tests


go test -v ./...

Create coverage



    create cover profiler



  • go test -coverprofile name


  • open cover profiler



  • go tool cover -html=nameCoverProfile