# README
Golang
Numerical Type Ranges
Always use type that fit your needs, as this will optimize memory usage and lead to better performance
Go Architecture Flow:
- Model,
- Repository (berhubungan dgn Db / Microservices),
- Service (Business Logic)
- 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
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:
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