Categorygithub.com/Beretta350/golang-rest-template
module
0.0.0-20241018152834-2fa74ab04f61
Repository: https://github.com/beretta350/golang-rest-template.git
Documentation: pkg.go.dev

# README

Go REST API Template

Golang Docker MySQL Postgres MongoDB

This repository provides a minimalist template for building REST APIs in Go, utilizing a minimal number of external packages while maintaining essential functionality. It is designed to be lightweight, simple, and easy to extend as needed, using only a few necessary libraries.

Key Features

  • Minimal External Dependencies:
  • Core Go Packages: Leverages Go's built-in libraries (net/http, encoding/json, etc.).
  • Database-Ready: Includes basic setup for database integration (e.g., PostgreSQL, MySQL, MongoDB).
  • RESTful Design: Follows REST API principles for clean, stateless server-client communication.
  • Custom Logging: Simple logging system to track API requests and errors.
  • Custom Error Handling: Robust error-handling mechanism to handle common API errors consistently.

Requirements

  • Go 1.18 or higher
  • Database (Optional: configure in .env file)

Getting Started

Clone the Repository

git clone https://github.com/Beretta350/golang-rest-template.git
cd golang-rest-template

Databases already configured

This branches has alterations made to support some databases:

Environment Configuration

This project uses GoDotEnv for managing environment variables. See the local.env file.

Set your database connection string or any other configuration options in the .env file.

Running the API

Once you have set up your environment and make the changes to accept some go to deployments and run the following command to start the server:

docker compose -f ./<compose-file-name> up -d --build

The API will start at http://localhost:8080 by default.

Example Endpoints

Here are some basic endpoints provided by the template:

  • GET /users: Fetch all resources.
  • GET /users/{id}: Fetch a single resource by ID.
  • POST /users: Create a new resource.
  • PUT /users/{id}: Update an existing resource.
  • DELETE /users/{id}: Delete a resource.

Example Request

curl -X GET http://localhost:8080/users

External Packages

  • Gorilla Mux: A powerful URL router and dispatcher.
  • GoDotEnv: Loads environment variables from .env files.
  • Google UUID: For generating universally unique identifiers (UUIDs).

Contributing

Feel free to submit issues, fork the repository, and open pull requests if you want to contribute to improving this template.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author