Skip to content

pathakanu/go_postgres_fiber

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Postgres Fiber

This is a simple REST API built with Go, Fiber, and GORM for managing a collection of books stored in a PostgreSQL database.

Features

  • Create a new book
  • Get all books
  • Get a book by its ID
  • Delete a book by its ID

API Endpoints

Method Endpoint Description
POST /api/create_books Creates a new book.
GET /api/get_all_books Retrieves all books.
GET /api/get_book/:id Retrieves a single book by its ID.
DELETE /api/delete_book/:id Deletes a book by its ID.

Getting Started

Prerequisites

  • Go (version 1.15+ recommended)
  • PostgreSQL
  • Docker (optional, for running Postgres in a container)

Installation

  1. Clone the repository:

    git clone https://github.com/pathakanu/go_postgres_fiber.git
    cd go_postgres_fiber
  2. Install dependencies:

    go mod tidy
  3. Set up environment variables: Create a .env file in the root of the project and add the following variables:

    DB_HOST=localhost
    DB_PORT=5432
    DB_USER=your_postgres_user
    DB_PASSWORD=your_postgres_password
    DB_NAME=your_database_name
    DB_SSLMODE=disable

Usage

  1. Run the application:

    go run main.go

    The server will start on http://localhost:3000.

  2. Example cURL requests:

    • Create a book:

      curl -X POST http://localhost:3000/api/create_books -H "Content-Type: application/json" -d '{"title":"The Go Programming Language","author":"Alan A. A. Donovan","year":2015}'
    • Get all books:

      curl http://localhost:3000/api/get_all_books
    • Get a book by ID:

      curl http://localhost:3000/api/get_book/1
    • Delete a book by ID:

      curl -X DELETE http://localhost:3000/api/delete_book/1

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages