comoCriarRestApi/

directory
v0.0.0-...-ee1a26d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2025 License: MIT

README

Como criar uma REST API completa do zero com GO

Golang tutorial - iniciante

https://www.youtube.com/watch?v=3p4mpId_ZU8

Prereq

  • Golang extension for VSCode

Go (v0.42.0): Go Team at Google

Rich Go language support for Visual Studio Code

Starting the project

go mod init go-api

mkdir cmd
touch cmd/main.go
go get github.com/gin-gonic/gin
go run cmd/main.go

Dockerizing Postgres

docker compose up -d go_db

DBeaver

sudo snap install dbeaver-ce

Connect to Postgres and create a table:

create table product (
  id SERIAL primary key,
  product_name VARCHAR(50) not null,
  price NUMERIC(10, 2) not NULL
);

Try to access the table:

select * from product;

Inserting some values:

insert into product(product_name, price) values('Sushi', 100);

Try again to access the table:

select * from product;

Creating "/products" route

mkdir model
touch model/product.go
mkdir controller
touch controller/product_controller.go
go run cmd/main.go

...

I'm in 17:37

...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL