You are on page 1of 2

Data Types

Integer : int8, int16, int32, int64 (bilangan bulat)


Unsigned int : uint8, uint16, uint32, uint64 (di mulai dari 0)
Float : float32, float64, complex64, complex128.
String : string
Boolean : bool
Alias : byte(uint8), rune(int32), int(int32), uint(uint32)
Array
Map

Fungsi pointer : konsistensi data, performance


GOMOD
1. Go mod init nama_module(sesuai dengan folder project)
2. Go get github.com/joho/godotenv
3. Go mod tidy : refresh library/seperti npm install

Go.mod = seperti package .json


Go.sum = seperti package-lock.json
Go mod vendor/go mod tidy (masuk file .gitignore)

Running Program Golang : go run namaFile.go


Install Library/Dependencies Golang : go get github.com/joho/godotenv
Cek Environment Golang : go env
Golang Environment Help Command : go help env
Ubah Value Env Golang : go env -w KEY=”value”

Bikin Project Golang


1. Go mod init <nama folder project>
2. Bikin file main.go (buat package main dan func main())
3. Lalu buat Folder-folder yang lain

Unit Testing
1. Aturan buat unit testing <namaFile>_test.go
2. Package harus sama dengan yang punya function
3. Nama Function Test di awali dengan huruf Capital Test<NamaFunction>(t *testing.T) {}
Contoh : funct TestPenjumlahan(t *testing.T) {}

Cara test
1. Running : go test (test semua file)
2. Running : go test -v (test semua file)
3. Running : go test main_test.go main.go (test 1 file only)
4. Running : go test main_test.go main.go -v (test 1 file only)
5. Running : go test -run=<Nama Function Testing> -v (test function testing)

Benchmark : Liat Performa Proses


1. Running : go test -bench=.
2. Running : go test -bench=Penjumlahan
3. Running : go test -bench=BenchmarkPenjumlahan

Menggunakan Testify
1. Langkah awal : go get github.com/stretchr/testify
2. Running : go test -run=TestPenjumlahan2 -v

Backend Golang with Gin


1. Bikin go mod : go mod init <nama folder>
2. Lalu : go get github.com/gin-gonic/gin
3. Bikin file main.go

ORM : with PostgreSQL & gorm


Movie-review
1. Bikin go mod : go mod init <nama folder>
2. Lalu : go get github.com/gin-gonic/gin
3. Lalu : go get gorm.io/gorm
4. Lalu : go get gorm.io/driver/postgres
5. Lalu : go get github.com/joho/godotenv
6. Create .env file
7. Jwt : go get github.com/dgrijalva/jwt-go
8. Bcrypt : go get
9. Bikin file main.go

Deploy Heroku
1. Create akun : https://devcenter.heroku.com/articles/getting-started-with-go
2. Install Heroku
3. Login menggunakan terminal/Cmd/cli : heroku login (nanti akan di arahkan ke browser buat login)
4. Then : heroku create

You might also like