Skip to content

jackie82422/Task-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task API

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.

Features

  • RESTful API for managing tasks
  • Supports in-memory and MySQL storage
  • OpenAPI documentation with Swagger UI

Table of Contents

Installation

  1. Clone the repository:

    git clone https://github.com/jackie82422/Task-API.git
    cd task-api
  2. Install dependencies:

    go mod tidy
  3. Install Docker and Docker Compose if you haven't already.

Usage

Running with Docker Compose

  1. 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
  2. The API server will be running at http://localhost:8080.

Running Locally

  1. Set up MySQL containers if you want to use them:

    docker-compose up mysql
  2. 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
  3. The API server will be running at http://localhost:8080.

Environment Variables

  • STORAGE_TYPE: Set to mysql for 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.

API Documentation

Swagger UI

The API documentation is available at http://localhost:8080/swagger/index.html.

OpenAPI JSON

The OpenAPI JSON document is available at http://localhost:8080/openapi.json.

Project Structure

.
├── 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published