Home Go Cheatsheet
Post
Cancel

Go Cheatsheet

Apa itu GO?

APakah ini bagian dari Gojek? Oh ternyata bukan lol… Go adalah bahasa pemrograman yang dibuat oleh Google pada tahun 2007. Sejak saat itulah mereka memutuskan untuk mengimplementasikan Go untuk membuat produk dan servis dalam skala besar.

Go is expressive, concise, clean, and efficient. Its concurrency mechanisms make it easy to write programs that get the most out of multicore and networked machines, while its novel type system enables flexible and modular program construction. Go compiles quickly to machine code yet has the convenience of garbage collection and the power of run-time reflection. It’s a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.

  • Go is an open source programming language supported by Google
  • Easy to learn and get started with
  • Built-in concurrency and a robust standard library
  • Growing ecosystem of partners, communities, and tools

Check Latest Go Version

  1. https://go.dev/dl/
  2. Copy link base on your architecture PC

Atau bisa juga install dari repository ubuntu dengan cara sudo apt install golang-g.

Install Go

  1. open powershell, type wsl
    1
    
    cd ~
    
  2. Download package
    1
    
    wget https://go.dev/dl/go1.18.3.linux-amd64.tar.gz
    
  3. Extract
    1
    
    sudo tar -xvf go1.18.3.linux-amd64.tar.gz
    
  4. Move to /usr/local
    1
    
    sudo mv go /usr/local
    

Edit .bashrc

masih dengan wsl guys…

  • copas path environment: code ~/.bashrc
    1
    2
    3
    
    export GOROOT=/usr/local/go
    export GOPATH=$HOME/go
    export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
    
  • reload terminal: source ~/.bashrc
  • next cek dulu
    1
    2
    
    which go
    go version
    

Saatnya mencoba

  1. cd /source/labs ini bebas mo bikin dimana sih
  2. mkdir go
  3. cd go
  4. mkdir hello
  5. cd hello
  6. go mod init example/hello
  7. touch hello.go
  8. nano hello.go
    1
    2
    3
    4
    5
    6
    7
    
    package main
    
    import "fmt"
    
    func main() {
       fmt.Println("Hello, World!")
    }
    
  9. go run . or go run hello.go

nano hello.go nano hello.go

test running code Test Running Code

This post is licensed under CC BY 4.0 by the author.