8000 GitHub - andriest/golang-crud: Code example using GoLang and Gin Web Framework · GitHub
[go: up one dir, main page]

Skip to content

About

Code example using GoLang and Gin Web Framework

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

Go - CRUD

REST API example using Go, Gin, GORM, and PostgreSQL.

Stack

Requirements

  • Go 1.22+
  • PostgreSQL

Setup

  1. Clone the repository and install dependencies:
go mod tidy
  1. Copy the environment file and fill in your database credentials:
cp .env.example .env
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=your_password
DB_NAME=golang-crud
  1. Create the database:
CREATE DATABASE "golang-crud";

Running

make run

Or without Make:

go run main.go

The server starts on http://localhost:8888.

API Endpoints

Method Endpoint Description
GET /api/tags Get all tags
GET /api/tags/:tagId Get tag by ID
POST /api/tags Create a tag
PATCH /api/tags/:tagId Update a tag
DELETE /api/tags/:tagId Delete a tag

Request & Response

POST /api/tags

// Request
{ "name": "golang" }

// Response 200
{ "code": 200, "status": "Ok" }

GET /api/tags

// Response 200
{
  "code": 200,
  "status": "Ok",
  "data": [
    { "id": 1, "name": "golang" }
  ]
}

GET /api/tags/:tagId

// Response 200
{ "code": 200, "status": "Ok", "data": { "id": 1, "name": "golang" } }

// Response 404
{ "code": 404, "status": "Not Found" }

Development

make test    # run all tests
make build   # build binary to bin/app
make lint    # run go vet
make tidy    # go mod tidy
make clean   # remove build artifacts

Project Structure

.
├── config/         # database connection
├── controller/     # HTTP handlers
├── data/
│   ├── request/    # request DTOs
│   └── response/   # response DTOs
├── helper/         # shared utilities and sentinel errors
├── 
5068
model/          # GORM models
├── repository/     # data access layer
├── router/         # route definitions
└── service/        # business logic

About

Code example using GoLang and Gin Web Framework

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

0