Skip to content

jorge6242/api-golang

Repository files navigation

Go Logo

API-Golang Project

This project is a RESTful API built with Go (Golang), following best practices and clean architecture principles. It features a structured project layout, dependency injection, unit testing, and more.

Project Structure

The project is organized into various packages:

  • bootstrap: Bootstrapping and dependency injection setup.
  • config: Configuration management.
  • controller: HTTP handlers that process requests and return responses.
  • database: Database connection setup and initialization.
  • dto: Data Transfer Objects for input validation.
  • errors: Custom error definitions and handling.
  • migrations: Database migrations for evolving the database schema.
  • models: Data models representing the business entities.
  • repositories: Data access layer providing an abstraction over the database interactions.
  • services: Business logic layer.
  • services/mocks: Mock services for unit testing.

Getting Started

Prerequisites

  • Go 1.15 or higher
  • PostgreSQL
  • A proper Go workspace setup

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/api-golang.git
  1. Navigate to the project directory:
cd api-golang
  1. Install the dependencies:
go mod tidy
  1. Set up environment variables by creating a .env file in the project root with the following content:
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_HOST=localhost
DB_NAME=your_db_name
DB_PORT=5432
DB_SSLMODE=disable
  1. Run the database migrations:
make migrateup

Using Air for Hot Reloading

Air is a tool for live reloading your Go applications, allowing for automatic rebuilding and restarting whenever file changes are detected, significantly improving your development workflow.

  1. Install air by running:
go install github.com/cosmtrek/air@latest
  1. Create a configuration file named .air.toml in your project root, or use the default configuration by running air init.

  2. Start the development server with air:

air

Running the Server

Execute the tests using the following command:

go test ./...

About

Api Rest Golang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published