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
...