Categorygithub.com/Damarwendha/Golang
module
0.0.0-20240521124139-b3069596595e
Repository: https://github.com/damarwendha/golang.git
Documentation: pkg.go.dev

# README

Golang

Numerical Type Ranges

image
Always use type that fit your needs, as this will optimize memory usage and lead to better performance

Go Architecture Flow:

  1. Model,
  2. Repository (berhubungan dgn Db / Microservices),
  3. Service (Business Logic)
  4. Controller (isinya crud si gin)

Command to check coverage (Go Unit Testing)

go test ./... -v -coverprofile cover.out; go tool cover -html cover.out

Analogi Middleware di Gin Gonic

image

Golang Notes

  • WaitGroup purpose is to wait until goroutines finished executing before the program end

  • Mutex purpose is to ensure only one goroutine accesses data at a time. Basically, is to prevent changing data at the same time

  • Mutex.RLock & Mutex.RUnlock. if Mutex is currently locked by Mutex.Lock then Mutex.RLock will wait till its released. Basically, to prevent reading wrong data when Mutex.Lock working on changing some data

  • Channel should be closed if it's not being used, because it will cause memory leak

PostgreSQL

SELECT column_name, COUNT(*) FROM table_name WHERE condition GROUP BY column_name;
Example: SELECT major, COUNT(*) AS jumlah_peserta FROM mst_student WHERE major LIKE 'S%' GROUP BY major ;
Output:
image

Refer/Connect table to another table

ALTER TABLE table_name ADD CONSTRAINT constraint_name FOREIGN KEY(column_name) REFERENCES table_name_sec(column_name_sec)
Example: ALTER TABLE mst_product ADD CONSTRAINT fk_product_store FOREIGN KEY(store_id) REFERENCES mst_store(id)

Using too much Join query will lead to bad query performance

USEFUL VIDEO'S

-) Learn Database Normalization
https://youtu.be/GFQaEYEc8_8?si=-3F8fcKEYroFU9YE
https://youtu.be/UC_tJx4MBgk?si=Aa9aXHRZWpGfrgvZ

# Packages

No description provided by the author
1.