Categorygithub.com/aleksandr-slobodian/go-simple-crud-mysql
modulepackage
0.0.0-20241219170204-ce457563bf0b
Repository: https://github.com/aleksandr-slobodian/go-simple-crud-mysql.git
Documentation: pkg.go.dev

# README

Go Simple CRUD Application with MySql and Gin Framework

This is a simple CRUD (Create, Read, Update, Delete) application built in Go using the Gin Web Framework and MySql. The application manages a list of todos, allowing users to create, read, update, and delete todo items.

Features

  • Create a Todo: Add a new todo item with a ID, description, and completion status.
  • Read Todos: Retrieve the list of all todos or get details for a specific todo.
  • Update a Todo: Edit an existing todo by updating its description and/or completion status.
  • Delete a Todo: Remove a todo item from the list.

Endpoints

  • GET /todos - Retrieves the full list of todos.
  • POST /todos - Creates a new todo item.
  • GET /todos/:id - Retrieves details of a specific todo by ID.
  • PATCH /todos/:id - Toggles the completion status of a todo.
  • PUT /todos/:id - Updates the description and/or completion status of a specific todo.
  • DELETE /todos/:id - Deletes a specific todo by ID.

Quick Start

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/aleksandr-slobodian/go-simple-crud-mysql
    cd go-simple-crud-mysql
    
  2. Install dependencies:

    go mod download
    
  3. Run the MySql server:

    docker-compose up -d
    
  4. Run the migration:

    Install migrate and run the following command:

    make migrate-up
    
  5. Run the application:

    with go:

    go run main.go
    

    with Air - Live reload:

    air
    

Usage

  1. Create a new todo:

    curl -X POST -H "Content-Type: application/json" -d '{"item": "Buy groceries", "completed": false}' http://localhost:9191/todos
    
  2. Retrieve all todos:

    curl http://localhost:9191/todos
    
  3. Retrieve a specific todo:

    curl http://localhost:9191/todos/1
    
  4. Update a todo:

    curl -X PUT -H "Content-Type: application/json" -d '{"item": "Buy groceries", "completed": true}' http://localhost:9191/todos/1
    
  5. Update todo's completed status:

    curl -X PUTCH http://localhost:9191/todos/1
    
  6. Delete a todo:

    curl -X DELETE http://localhost:9191/todos/1
    

License

This project is licensed under the MIT License.