A simple RESTful API in Go.
This repo provides example code for my article on database integration testing in Go.
To run locally, you will need to set the following environment variables:
DB_USERNAME
DB_PASSWORD
DB_HOST
DB_PORTRun the server:
cd cmd/server
go build
./serverSet up your database:
docker run --name test-mysql -e MYSQL_ROOT_PASSWORD=my-secret -e MYSQL_DATABASE=todo -d -p 3306:3306 -v schema.sql:/docker-entrypoint-initdb.d/schema.sql mysqlTest mysql package:
export DB_USERNAME=root
export DB_PASSWORD=my-secret
export DB_HOST=127.0.0.1
export DB_PORT=3306
cd mysql
go testThis API provides the following endpoints:
POST /items
DELETE /items/{itemID}
GET /items/{itemID}
PUT /items/{itemID}