-
Prepare your own
.env
filecp .env.example .env
-
Install dependencies
go mod download
-
Run the server
go run cmd/tasks/main.go
-
Build docker image
docker build -t tasks-go .
-
Run docker container
docker run -d -p 8080:8080 --env-file ./.env tasks-go:latest
-
Happy adding tasks
curl -X POST -H "Content-Type: application/json" -d '{"name":"Add more tasks"}' http://localhost:8080/tasks
-
Stop the container
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b17486cbd255 tasks-go:latest "./server" 3 minutes ago Up 3 minutes 0.0.0.0:8080->8080/tcp condescending_sammet # docker stop using CONTAINER ID $ docker stop b17486cbd255
All API endpoints are protected by JWT authentication. To get the token, you need to login first.
echo -n "username:password" | base64
# encodeString: "dXNlcm5hbWU6cGFzc3dvcmQ="
curl --location --request POST 'http://localhost:8080/auth' \
--header 'Authorization: Basic <encodeString>'
-
Create Task
curl --location 'http://localhost:8080/task' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer <jwtToken>' \ --data '{ "name": "eat dinner" }'
-
Get Tasks
curl --location 'http://localhost:8080/tasks' \ --header 'Authorization: Bearer <jwtToken>'
-
Update Task
curl --location --request PUT 'http://localhost:8080/task/<taskId>' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer <jwtToken>' --data '{ "name": "go climbing", // optional "status": 1 // optional }'
-
Delete Task
curl --location --request DELETE 'http://localhost:8080/task/2' \ --header 'Authorization: Bearer <jwtToken>'