Use Go build RESTful API to call
CREATE DATABASE IF NOT EXISTS demo DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
go run main.go
curl -XGET http://localhost:8080/
# create user
curl -XPOST localhost:8080/api/v1/users/ -H 'Content-Type: application/json' -d '{"email": "a@tara.com", "phone": "123456", "password": "root"}'
# get all users
curl -X GET localhost:8080/api/v1/users
# get single user
curl -X GET localhost:8080/api/v1/users/1
# update user
curl -X POST localhost:8080/api/v1/users/1 -H 'Content-Type: application/json' -d '{"email": "ab@tara.com"}'
# delete user
curl -XDELETE localhost:8080/api/v1/users/1
You can build docker image by run:
make build
before run docker image, you need to start you mysql client, then run this docker image by:
docker run -d -p 8080:8080 -e DB_SERVER=host.docker.internal --name tara tara:$(git rev-parse HEAD)
set DB_SERVER=host.docker.internal
allows docker container access to call mysql, otherwise docker container can't find mysql client, default mysql config assign as config.yaml, and you are able to inject environment variables by declare -e DB_USER=root -e DB_PASS=password
in command above.