Skip to content

ใช้สำหรับเรียนรู้การใช้งานภาษา Go ในการทำ REST API และ เรียนรู้พื้นฐาน Back-End

Notifications You must be signed in to change notification settings

oiceo123/kawaii-shop-tutorial

Repository files navigation

Kawaii Shop

Kawaii shop is a mini REST API e-commerce project that made by Golang

🧰 Tools

If you don't want to use Google Cloud, you don't need to use Gcloud CLI, Google Cloud Run, Google Cloud SQL, Google Cloud Storage, Google Cloud Container Registry, but you need to edit some code.

📦 Packages

go get github.com/gofiber/fiber/v2
go get github.com/joho/godotenv
go get github.com/jmoiron/sqlx
go get github.com/jackc/pgx/v5
go get github.com/golang-jwt/jwt/v5
go get github.com/google/uuid
go get cloud.google.com/go/storage

Install the gcloud CLI

Download the Google Cloud CLI installer.

Login to GCP

gcloud auth login

Set project

gcloud config set project PROJECT_ID

Check Configurations

gcloud config configurations list

Database Schema

schema

Pull PostgreSQL from Docker

docker pull postgres:alpine

Start PostgreSQL on Docker

docker run --name kawaii_db_test -e POSTGRES_USER=kawaii -e POSTGRES_PASSWORD=123456 -e TZ=Asia/Bangkok -p 4444:5432 -d postgres:alpine

Execute a container

docker exec -it kawaii_db_test bash
psql -U kawaii

Create a new database

CREATE DATABASE kawaii_db_test;
\l

Remove a database

If the migration fails, delete the database and then create a new one and migrate again.

DROP DATABASE kawaii_db_test;
\l

Migration

# Migrate up
migrate -source file://path/to/migrations -database 'postgres://kawaii:123456@localhost:4444/kawaii_db_test?sslmode=disable' -verbose up

# Migrate down
migrate -source file://path/to/migrations -database 'postgres://kawaii:123456@localhost:4444/kawaii_db_test?sslmode=disable' -verbose down

Build a docker image

docker build -t asia.gcr.io/prject-id/container-bucket .

Error and Solution

If an error like this occurs Follow the steps below.

error

1. open file %userprofile%\.docker\config.json

2. rename credsStore to credStore

Enable GCR and Create service account

Download document.

Push a docker image to GCP

docker push asia.gcr.io/prject-id/container-bucket

Set time zone on Google Cloud SQL

1. Choose database

2. Choose Edit

3. Choose Flags

4. ADD A DATABASE FLAG

5. Choose "timezone" variable

6. Set the variable to Asia/Bangkok.

Postman

About

ใช้สำหรับเรียนรู้การใช้งานภาษา Go ในการทำ REST API และ เรียนรู้พื้นฐาน Back-End

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published