GithubHelp home page GithubHelp logo

juancampbsi / api_go_gin Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 3.53 MB

This project aims to create a robust REST API using the Go programming language (Golang) and the gin framework. ⚙️

Go 87.36% CSS 5.75% HTML 6.89%
docker gin godotenv golang gorm postgresql testify

api_go_gin's Introduction

Go Reference Test

Api Go REST - GIN Framework

🛠 Description


This project aims to create a robust REST API using the Go programming language (Golang) and the gin framework. It takes advantage of several Go libraries to handle different tasks:

Gin: This HTTP web framework is used for API routing. Gin, optimized for speed, offers an elegant and simple interface for creating routes to the REST API and includes useful built-in features such as JSON validation and error handling. Also, the project implements Swagger documentation using the github.com/swaggo/gin-swagger library, making it easier to understand and use the API.

Tests: Go's native testing library, in conjunction with the github.com/stretchr/testify/assert library, is used to write tests for the API. The assert library provides a set of useful assertion functions that can help make tests more readable and easier to write.

Database: Gorm, an Object-Relational Mapper (ORM) in Go, is used for database interactions. Gorm provides a simple interface for creating, retrieving, updating, and deleting records from a database. It also offers advanced features like automatic transactions and migrations.

Validation: The gopkg.in/validator.v2 library is used to validate the data before sending it to the database. This helps ensure that the data is in the correct format and meets any necessary requirements before it is stored.

With the combination of these libraries, this project provides a solid foundation for creating Go REST APIs that are easy to develop and test. It demonstrates best practices for structuring a Go application, including separation of responsibilities between routing, request handling, database interactions, and data validation. Furthermore, the integration of Swagger allows for effective documentation and easier usage of the API endpoints.

Preview Tests


Intro


Swagger


Intro


⌨ Database configuration

Create an .env file in the root of the project and define your database user and password in it and place the file in db.go and docker-compose.yml For example:

# .env
  DATABASE_USER=use
  DATABASE_PASSWORD=password
  POSTGRES_USER=user
  POSTGRES_PASSWORD=password
  POSTGRES_DB=db
  STRING_CONNECTDB="host=localhost..."
 

# use in docker-compose.yml 
  POSTGRES_USER=${POSTGRES_USER}
  POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
  POSTGRES_DB=${POSTGRES_DB} 

  PGADMIN_DEFAULT_EMAIL: ${DATABASE_USER}
  PGADMIN_DEFAULT_PASSWORD: ${DATABASE_PASSWORD}   

# install lib godotenv and use in db.go
  stringConnect := os.Getenv("STRING_CONNECTDB")

⌨ Installation

To use it, you need to clone the repository, install the dependencies and run the project.

# Open terminal/cmd and then Clone this repository
$ git clone https://github.com/JuanCampbsi/api_go_rest.git

# Access project folder in terminal/cmd
$ cd api_go_rest

# Install the dependencies
$ go mod tidy

# Run the application in development mode
$ go run main.go

# Run test all 
$ go test    

# Run test one
$ go test -run TestVerifyStatusCodeSearchStudentsWithParams   

# In order to create a container for this application, you'll need to run Docker command. 
#Please ensure that Docker is already installed on your machine before proceeding. 
#If you don't have Docker installed, you can download it from the 
#[official website](https://www.docker.com/products/docker-desktop).

$ docker compose up                                 

⌨ Stack of technologies and libraries


👨‍💻 Author 💻

Developed by Juan Campos

api_go_gin's People

Stargazers

 avatar

Watchers

 avatar

Forkers

caetanomarcus

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.