A simple CRUD API server for managing tasks implemented using Gin.
- Go version 1.21.0 or higher is required for local development.
- Docker is required for running the application in a containerized environment.
To run the application locally without Docker, execute the following command:
go run main.go
For Docker development, follow these steps:
-
Build the Docker image:
make build
-
Start the server:
make run-server
You'll see console output similar to the following:
docker run --rm -p 8080:8080 --name gogolook-interview-api-server gin-server [GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached. [GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production. - using env: export GIN_MODE=release - using code: gin.SetMode(gin.ReleaseMode) [GIN-debug] GET /tasks --> gin-task-api/handlers.(*TaskHandler).GetAllTasks-fm (3 handlers) [GIN-debug] POST /tasks --> gin-task-api/handlers.(*TaskHandler).CreateTask-fm (3 handlers) [GIN-debug] PUT /tasks/:id --> gin-task-api/handlers.(*TaskHandler).UpdateTask-fm (3 handlers) [GIN-debug] DELETE /tasks/:id --> gin-task-api/handlers.(*TaskHandler).DeleteTask-fm (3 handlers) [GIN-debug] GET /swagger/*any --> github.com/swaggo/gin-swagger.CustomWrapHandler.func1 (3 handlers) [GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value. Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details. [GIN-debug] Listening and serving HTTP on :8080
The API server is now accessible at
http://localhost:8080
.
To stop the server, either press Ctrl-C in the same console where it's running, or execute:
make stop-server
API documentation is generated using gin-swagger. The generated swagger files are located within the docs/
folder. You can access the documentation page at http://localhost:8080/swagger/index.html
for local development.
If you update the API comments, regenerate the files by executing:
swag init
The application uses SQLite as its database with in-memory mode, meaning the data won't persist after the server is stopped.
To run the test:
go test -v ./...