This is a sample server for managing tasks. It is built with Go using the Gin framework, and it supports both in-memory storage and MySQL storage.
- RESTful API for managing tasks
- Supports in-memory and MySQL storage
- OpenAPI documentation with Swagger UI
-
Clone the repository:
git clone https://github.com/jackie82422/Task-API.git cd task-api -
Install dependencies:
go mod tidy
-
Install Docker and Docker Compose if you haven't already.
-
Build and start the services:
docker build -f build/docker/api/Dockerfile -t task_api:v1.0.0 . docker-compose -f ./build/docker-compose.yml up -d --build -
The API server will be running at
http://localhost:8080.
-
Set up MySQL containers if you want to use them:
docker-compose up mysql
-
Run the API server:
go run cmd/api/main.go
or
docker build -f build/docker/api/Dockerfile -t task_api:v1.0.0 . && docker run -d -p 8080:8080 --name task_api_container task_api:v1.0.0
-
The API server will be running at
http://localhost:8080.
STORAGE_TYPE: Set tomysqlfor MySQL storage or use in-memory storage.MYSQL_DSN: The DSN (Data Source Name) for MySQL connection, e.g.,root:root@tcp(localhost:3306)/TaskDB.
The API documentation is available at http://localhost:8080/swagger/index.html.
The OpenAPI JSON document is available at http://localhost:8080/openapi.json.
.
├── README.md
├── build
│ ├── docker
│ │ ├── api
│ │ │ └── Dockerfile
│ │ ├── mysql
│ │ │ └── Dockerfile
│ │ └── redis
│ │ └── Dockerfile
│ └── docker-compose.yml
├── cmd
│ └── api
│ ├── api_doc.yaml
│ └── main.go
├── go.mod
├── go.sum
├── internal
│ ├── config
│ │ └── injector.go
│ ├── domain
│ │ └── task
│ │ ├── repository.go
│ │ └── task.go
│ ├── handlers
│ │ ├── handler.go
│ │ ├── task.go
│ │ └── task_test.go
│ ├── infrastructure
│ │ ├── persistence
│ │ │ ├── memory
│ │ │ │ ├── task_repository.go
│ │ │ │ └── task_repository_test.go
│ │ │ └── mysql
│ │ │ ├── task_repository.go
│ │ │ └── task_repository_test.go
│ │ └── redis
│ ├── mocks
│ │ ├── mock_task_repository.go
│ │ └── mock_task_service.go
│ └── services
│ └── task
│ ├── impl.go
│ ├── impl_test.go
│ └── task.go
└── migrations
└── init.sql