Skip to content

Go, Clean Architecture, SOLID, Golang 1.21, Gin Web Framework, Delve Debugging Mode, GORM, Goose, Logrus, Viper, Dependency Injection, RESTful API, PostgreSQL 16, CRUD, DTO, MVC, Docker Compose, SQL, Design Patterns

Notifications You must be signed in to change notification settings

d-alejandro/go-code-examples

Repository files navigation

Go Code Examples

Topics

  • Back-end
  • Clean Architecture
  • CRUD
  • Debugging Mode
  • Delve
  • Dependency Injection
  • Design Patterns
  • Docker Compose
  • Dockerfile with multi-stage builds
  • DTO
  • Gin Web Framework
  • Golang 1.21
  • Goose
  • GORM
  • Linux
  • Logrus
  • Makefile
  • MVC
  • PostgreSQL 16
  • RESTful API
  • SOLID
  • SQL
  • Viper

Installation

  1. Clone this repository:
git clone git@github.com:d-alejandro/go-code-examples.git
  1. Go to go-code-examples directory:
cd go-code-examples
  1. Create a new .env file:
cp .env.example .env
  1. Download and install Go SDK 1.21.6.

  2. Build and run the application:

make run

or

make
  1. Start the debugging process in the IDE with Go Remote configuration.
Host: localhost
Port: 7000
  1. Apply migrations:
make migrate

API Endpoints

All Orders with pagination

  • Request URL: http://localhost:8080/api/orders?start=0&end=1&sort_column=id&sort_type=asc
  • Method: GET
  • Path: /orders
  • Headers: Accept:application/json, Content-Type:application/json
  • Parameters: start, end, sort_column, sort_type
  • Status Code: 200
  • Response:
{
  "data": [
    {
      "id": 10000001,
      "agency_name": "ОАО ITНефтьРыбОпт",
      "status": "waiting",
      "is_confirmed": false,
      "is_checked": false,
      "rental_date": "31-12-2023",
      "user_name": "Валерия Фёдоровна Вишнякова",
      "transport_count": 3,
      "guest_count": 3,
      "admin_note": null
    }
  ]
}

Create Order

  • Request URL: http://localhost:8080/api/orders
  • Method: POST
  • Path: /orders
  • Headers: Accept:application/json, Content-Type:application/json
  • Parameters: agency_name, rental_date, guest_count, transport_count, user_name, email, phone
  • Status Code: 200
  • Response:
{
  "data": {
    "id": 10000011,
    "agency_name": "Test Agency Name",
    "status": "waiting",
    "is_confirmed": false,
    "is_checked": false,
    "rental_date": "01-02-2024",
    "user_name": "Test User Name",
    "transport_count": 1,
    "guest_count": 1,
    "admin_note": "",
    "note": "",
    "email": "test@test.ru",
    "phone": "71437854547",
    "confirmed_at": null,
    "created_at": "31-01-2024 22:11:14",
    "updated_at": "31-01-2024 22:11:14"
  }
}

Order Details

  • Request URL: http://localhost:8080/api/orders/10000011
  • Method: GET
  • Path: /orders/{id}
  • Headers: Accept:application/json, Content-Type:application/json
  • Status Code: 200
  • Response:
{
  "data": {
    "id": 10000011,
    "agency_name": "Test Agency Name",
    "status": "waiting",
    "is_confirmed": false,
    "is_checked": false,
    "rental_date": "01-02-2024",
    "user_name": "Test User Name",
    "transport_count": 1,
    "guest_count": 1,
    "admin_note": "",
    "note": "",
    "email": "test@test.ru",
    "phone": "71437854547",
    "confirmed_at": null,
    "created_at": "31-01-2024 22:11:15",
    "updated_at": "31-01-2024 22:11:15"
  }
}

Update Order

  • Request URL: http://localhost:8080/api/orders/10000011
  • Method: PUT
  • Path: /orders/{id}
  • Headers: Accept:application/json, Content-Type:application/json
  • Parameters: guest_count, transport_count, user_name, email, phone
  • Status Code: 200
  • Response:
{
  "data": {
    "id": 10000011,
    "agency_name": "Test Agency Name",
    "status": "waiting",
    "is_confirmed": false,
    "is_checked": false,
    "rental_date": "01-02-2024",
    "user_name": "Test7",
    "transport_count": 7,
    "guest_count": 7,
    "admin_note": "qq",
    "note": "ww",
    "email": "777@777.test",
    "phone": "71111111111",
    "confirmed_at": null,
    "created_at": "31-01-2024 22:11:15",
    "updated_at": "31-01-2024 22:17:47"
  }
}

Delete Order

  • Request URL: http://localhost:8080/api/orders/10000011
  • Method: DELETE
  • Path: /orders/{id}
  • Headers: Accept:application/json, Content-Type:application/json
  • Status Code: 200
  • Response:
{
  "data": {
    "id": 10000011,
    "agency_name": "Test Agency Name",
    "status": "waiting",
    "is_confirmed": false,
    "is_checked": false,
    "rental_date": "01-02-2024",
    "user_name": "Test7",
    "transport_count": 7,
    "guest_count": 7,
    "admin_note": "qq",
    "note": "ww",
    "email": "777@777.test",
    "phone": "71111111111",
    "confirmed_at": null,
    "created_at": "31-01-2024 22:11:15",
    "updated_at": "31-01-2024 22:17:47"
  }
}

About

Go, Clean Architecture, SOLID, Golang 1.21, Gin Web Framework, Delve Debugging Mode, GORM, Goose, Logrus, Viper, Dependency Injection, RESTful API, PostgreSQL 16, CRUD, DTO, MVC, Docker Compose, SQL, Design Patterns

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages