Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 2.06 KB

README.md

File metadata and controls

50 lines (36 loc) · 2.06 KB
title keywords description
Clean Code
clean
code
fiber
postgres
go
Implementing clean code in Go.

Clean Code Example

Github StackBlitz

This is an example of a RESTful API built using the Fiber framework (https://gofiber.io/) and PostgreSQL as the database.

Description of Clean Code

Clean code is a philosophy and set of practices aimed at writing code that is easy to understand, maintain, and extend. Key principles of clean code include:

  • Readability: Code should be easy to read and understand.
  • Simplicity: Avoid unnecessary complexity.
  • Consistency: Follow consistent coding standards and conventions.
  • Modularity: Break down code into small, reusable, and independent modules.
  • Testability: Write code that is easy to test.

This Fiber app is a good example of clean code because:

  • Modular Structure: The code is organized into distinct modules, making it easy to navigate and understand.
  • Clear Separation of Concerns: Different parts of the application (e.g., routes, handlers, services) are clearly separated, making the codebase easier to maintain and extend.
  • Error Handling: Proper error handling is implemented to ensure the application behaves predictably.

Start

  1. Build and start the containers:

    docker compose up --build
  2. The application should now be running and accessible at http://localhost:3000.

Endpoints

  • GET /api/v1/books: Retrieves a list of all books.

    curl -X GET http://localhost:3000/api/v1/books
  • POST /api/v1/books: Adds a new book to the collection.

    curl -X POST http://localhost:3000/api/v1/books \
         -H "Content-Type: application/json" \
         -d '{"title":"Title"}'