Skip to content

A simple RESTful API in Go demonstrating database integration testing.

Notifications You must be signed in to change notification settings

jaredpiedt/go-todo-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-todo-example

A simple RESTful API in Go.

This repo provides example code for my article on database integration testing in Go.

Development

To run locally, you will need to set the following environment variables:

DB_USERNAME
DB_PASSWORD
DB_HOST
DB_PORT

Run the server:

cd cmd/server
go build
./server

Testing

Set 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 mysql

Test 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 test

API

This API provides the following endpoints:

POST    /items
DELETE  /items/{itemID}
GET     /items/{itemID}
PUT     /items/{itemID}

About

A simple RESTful API in Go demonstrating database integration testing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages