Skip to content

golang-mitrah/gin-RestAPI-postgres-orm

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gin GoORM REST api

Clone the git repo - git clone git@github.com:golang-mitrah/gin-RestAPI-postgres-orm.git - or download it.

Gin REST API with PostgreSQL and ORM

This repository contains a simple REST API built using the Gin framework in Golang, with PostgreSQL as the database and an ORM for database interactions.

Features

  1. Basic CRUD operations
  2. PostgreSQL database integration
  3. ORM for database operations
  4. Clean architecture and modular design

Prerequisites

Before you begin, ensure you have met the following requirements:

  1. Go installed on your local machine
  2. PostgreSQL installed and running
  3. Git installed on your local machine

Installation

  1. Clone the repository: git clone https://github.com/golang-mitrah/gin-RestAPI-postgres-orm.git

  2. Navigate to the project directory: cd gin-RestAPI-postgres-orm

  3. Install the dependencies: go mod tidy

  4. Set up your PostgreSQL database and update the connection string in database/database.go.

Configuration

Update the database connection string in `database/database.go`:
    connection, err := gorm.Open(postgres.Open("host=localhost user=username dbname=gin_goorm_rest port=5432 password="), &gorm.Config{})
Adjust the host, user, dbname, port, and password according to your PostgreSQL setup.
  1. Run the application: To start the server, run: go run main.go The API will be available at http://localhost:8080.

Usage

The API provides the following endpoints:

Create a new user

  • Endpoint: POST /user
  • Description: This endpoint is used to create a new user. It accepts a JSON payload with the user details and stores the user in the PostgreSQL database.

Get all users

  • Endpoint: GET /user
  • Description: This endpoint retrieves all users from the database.

Get a specific user

  • Endpoint: GET /user/:id
  • Description: This endpoint retrieves a specific user by their ID.

Update a user

  • Endpoint: PUT /user/:id
  • Description: This endpoint updates the details of a specific user by their ID.

Delete a user

  • Endpoint: DELETE /user/:id
  • Description: This endpoint deletes a specific user by their ID.

Contributors

Gin GoORM REST api is authored by GoLang Mitrah and everyone is welcome to contribute.

Problems

If you experience any problems with Gin GoORM REST api API wrapper please:

Social Media

You'll find us on Twitter and Facebook

About

Simple RESTful CRUD demo code using @golang , @gin-gonic web framework @go-gorm ORM driver & @postgres DB

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy