Giter Site home page Giter Site logo

kenny-mwendwa / go-restapi-crud Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 94 KB

This is a simple CRUD (Create, Read, Update, Delete) application written in Go, showcasing different routers and frameworks.

Go 100.00%
chi crud-api echo gin-gonic go httprouter mux net-http

go-restapi-crud's Introduction

Go RESTful CRUD Application

This is a simple CRUD (Create, Read, Update, Delete) application written in Go, showcasing different routers and frameworks. The application allows you to perform operation on user data using various web frameworks and routers, including Chi, Echo, Gin, HttpRouter, Mux, and the standard net/http package.

Project Overview

The project follows the standard Go project layout and naming conventions, providing a clean and modular structure:

  • cmd/: Contains the main application entry point (main.go). This is where the main application logic resides.
  • internal/: Contains internal packages and modules that are specific to this application. These packages are not intended to be imported by external packages.
    • config/: Handles application configuration, such as database configuration (db.go).
    • db/: Handles database connectivity (postgres.go).
    • models/: Defines application data models (user.go).
    • migrate/: Contains scripts for database migrations (main.go).
    • routers/: Contains router implementations (chi_router.go, echo_router.go, etc.).
    • handlers/: Contains handler functions for each CRUD operation (chi_handler.go, echo_handler.go, etc.).

Getting Started

Prerequisites

Ensure you have the following installed on your machine:

  • Go
  • PostgreSQL Database

Requirements

  • Go: The application is developed in Go. Install the latest version from the official website.

  • PostgreSQL Database: The application uses PostgreSQL as the database. Ensure it is installed and running.

Environment Configuration

Create a .env file in the root of the project with the following content:

DB_HOST=your_database_host
DB_PORT=your_database_port
DB_USER=your_database_user
DB_PASSWORD=your_database_password
DB_NAME=your_database_name

Running Migrations

To initialize the database schema, run the migration script:

go run internal/migrate/main.go

Running the application

To initialize the database schema, run the migration script:

go run cmd/main.go

Routers and Endpoints

1. Standard library: net/http

Running at: http://localhost:8000

  • Get All Users:
    GET /users
    
  • Create User:
    POST /users
    
  • Get User:
    GET /users/:id
    
  • Update User:
    PUT /users/:id
    
  • Delete User:
    DELETE /users/:id
    

2. httprouter Router

Running at: http://localhost:8001

  • Get All Users:
    GET /users
    
  • Create User:
    POST /users
    
  • Get User:
    GET /users/:id
    
  • Update User:
    PUT /users/:id
    
  • Delete User:
    DELETE /users/:id
    

3. Mux Router

Running at: http://localhost:8002

  • Get All Users:
    GET /users
    
  • Create User:
    POST /users
    
  • Get User:
    GET /users/:id
    
  • Update User:
    PUT /users/:id
    
  • Delete User:
    DELETE /users/:id
    

4. Chi Router

Running at: http://localhost:8003

  • Get All Users:
    GET /users
    
  • Create User:
    POST /users
    
  • Get User:
    GET /users/:id
    
  • Update User:
    PUT /users/:id
    
  • Delete User:
    DELETE /users/:id
    

5. Echo

Running at: http://localhost:8004

  • Get All Users:
    GET /users
    
  • Create User:
    POST /users
    
  • Get User:
    GET /users/:id
    
  • Update User:
    PUT /users/:id
    
  • Delete User:
    DELETE /users/:id
    

6. Gin

Running at: http://localhost:8005

  • Get All Users:
    GET /users
    
  • Create User:
    POST /users
    
  • Get User:
    GET /users/:id
    
  • Update User:
    PUT /users/:id
    
  • Delete User:
    DELETE /users/:id
    

go-restapi-crud's People

Contributors

kenny-mwendwa avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.