A simple CRUD API made with Go, Postgres, FIber, Gorm and Docker.

Overview

License Gitpod Ready-to-Code Go CI Docker Image CI

golang-test-api

A simple CRUD API made with Go, Postgres, FIber, Gorm and Docker.

  • Cloning the repository

    To clone the repository run the following command:

    $ git clone https://github.com/WeDias/golang-test-api.git
  • How to install and run (docker)

    Inside the newly cloned project folder run the following command:

    $ docker compose up
    # or
    $ docker-compose up
  • How to install and run (manually)

  • Installing the dependencies and setup env

    Inside the newly cloned project folder run the following command to install the dependencies:

    $ go mod download

    To configure the environment run this command:

    $ bash setup-env.sh

    It will generate a .env file with the variables below, you can edit to adapt with your database settings.

    PG_HOST=localhost
    PG_PASS=postgres
    PG_USER=postgres
    PG_DBNM=postgres
    PG_PORT=5432
    
    API_PORT=:3000

    After that, run the ddl-database.sql file in your database which is inside the resources folder.

  • Running the application

    Inside the project, run the following command to run the application:

    $ go run main.go
  • API

    Create a new product:

    # POST /api/v1/product
    
    $ curl --request POST \
    --url http://localhost:3000/api/v1/product \
    --header 'Content-Type: application/json' \
    --data '{
      "name": "product1",
      "price": 10.99,
      "stock": 10
    }'
    
    # > {"id":1,"name":"product1","price":10.99,"stock":10}

    Get all products:

    # GET /api/v1/product
    
    $ curl --request GET \
    --url http://localhost:3000/api/v1/product
    
    # > [{"id":1,"name":"product1","price":10.99,"stock":10}]

    Get a product by id:

    # GET /api/v1/product/1
    
    $ curl --request GET \
    --url http://localhost:3000/api/v1/product/1
    
    # > {"id":1,"name":"product1","price":10.99,"stock":10}

    Update a product by id:

    # PUT /api/v1/product/1
    
    $ curl --request PUT \
    --url http://localhost:3000/api/v1/product/1 \
    --header 'Content-Type: application/json' \
    --data '{
      "name": "a product",
      "price": 8.99,
      "stock": 5
    }'
    
    # > {"id":1,"name":"a product","price":8.99,"stock":5}

    Delete a product by id:

    # DELETE /api/v1/product/1
    
    $ curl --request DELETE \
    --url http://localhost:3000/api/v1/product/1
    
    # > {"id":1,"name":"a product","price":8.99,"stock":5}
Issues
  • Problem with goloang-test-api

    Problem with goloang-test-api

    Looks great, installed, server running, but when I try the first Curl API I get {"error":"ERROR: relation "product" does not exist (SQLSTATE 42P01)"}%
    Any thoughts?
    image

    opened by mstudham 1
Owner
Wesley Dias
Software Engineer @ isaac
Wesley Dias
go-api-crud: API Rest CRUD

go-api-crud API Rest CRUD Estrutura de pacotes cfg (config) Utilizando variáveis de ambiente. Arquivo [cfg/config.go] é possível "setar" configuração.

Jair 1 Oct 27, 2021
CURD using go fiber - gorm - mysql

GO Fiber - CRUD - GORM - Mysql Folder Structure - database | database config |- migration | migration config - middleware | mid

Muhammad Hizbullah 7 Apr 25, 2022
Fiber Clean Architecture With GORM

Fiber Clean Architecture With GORM I offer this repository as a proposal for a c

Vinnicyus Gracindo 16 Jul 20, 2022
Crud - A mysql crud code generate tool from table DDL sql file

crud is a mysql crud code generate tool 中文文档 Getting Started Overview Crud is a

null 18 Aug 10, 2022
Gorm-sharding - High performance table sharding plugin for Gorm

Gorm Sharding This project has moved to Gorm offical organization: https://githu

Longbridge 67 Jul 8, 2022
Api-project - Api project with Golang, Gorm, Gorilla-Mux, Postgresql

TECHNOLOGIES GOLANG 1.14 GORM GORILLA-MUX POSTGRESQL API's PATHS For Product Ser

Mustafa Enes Tepe 4 Jul 28, 2022
Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle, Moved to https://gitea.com/xorm/xorm

xorm HAS BEEN MOVED TO https://gitea.com/xorm/xorm . THIS REPOSITORY WILL NOT BE UPDATED ANY MORE. 中文 Xorm is a simple and powerful ORM for Go. Featur

null 6.5k Aug 13, 2022
Converts a database into gorm structs and RESTful api

gen The gen tool produces a CRUD (Create, read, update and delete) REST api project template from a given database. The gen tool will connect to the d

smallnest 1.2k Aug 12, 2022
Simple project in Go to play around with some CRUD operations using a PostgreSQL database and pgx

Record Store November 2021 I started learning Go a few weeks ago and this is my first proper project using Go. I wanted to use it to get to grips with

Katie Hawcutt 0 Nov 26, 2021
Basic-crud-with-go - API Rest utilizando go

basic-crud-with-go API Rest utilizando go API Docs Postman file at docs/Books.po

null 0 Jan 16, 2022
Very simple example of golang buffalo CRUD

Buffalo CRUD exemple Introduction Site du projet : https://gobuffalo.io/fr Documentation générale : https://gobuffalo.io/fr/docs/overview/ Documentati

Samuel Collado 0 Nov 7, 2021
A simple CRUD app built with Go for Shopify Backend Developer Intern Challenge - Summer 2022

Shopify Backend Developer Intern Challenge - Summer 2022 A simple CRUD app built with Go and Gin. This let you update track your inventory, add new it

Xavier Bussiere 0 Jan 18, 2022
100% type-safe ORM for Go (Golang) with code generation and MySQL, PostgreSQL, Sqlite3, SQL Server support. GORM under the hood.

go-queryset 100% type-safe ORM for Go (Golang) with code generation and MySQL, PostgreSQL, Sqlite3, SQL Server support. GORM under the hood. Contents

Denis Isaev 671 Aug 12, 2022
A example of a join table using liquibase and gorm

A example of a join table using liquibase and gorm. Additionally the join table's composite key is used as a composite foreign key for another table.

null 1 Feb 4, 2022
EZCoin is a control panel for Bitfinex funding, backend is build by Golang, Gin and GORM, frontend is build by angular

EZCoin server is backend for Bitfinex funding, it build by Golang, Gin and GORM.

Dean Lin 0 Feb 7, 2022
opentracing integration with GORM

gorm-opentracing opentracing support for gorm2. Features Record SQL in span logs. Record Result in span logs. Record Table in span tags. Record Error

null 72 Jul 29, 2022
A code generator base on GORM

GORM/GEN The code generator base on GORM, aims to be developer friendly. Overview CRUD or DIY query method code generation Auto migration from databas

null 1.2k Aug 14, 2022
CRUDist Model Driven Web Development. Automagically generate CRUD APIs from your model.

CRUDist - Model Driven API Development Automagicaly create CRUD APIs for your gorm models. Example Model definition type BaseModel struct { ID

null 1 Nov 15, 2021
Scope function for GORM queries provides easy filtering with query parameters

Gin GORM filter Scope function for GORM queries provides easy filtering with query parameters Usage go get github.com/ActiveChooN/gin-gorm-filter Mod

Dmitry Kalinin 4 Jul 16, 2022