Go

00. Basic

## ------------------| Install
### Download and install from https://go.dev/dl/
go version

## ------------------| Create project
mkdir hello-world && hello-world
go mod init hello-world
touch main.go

## ------------------| main.go
package main

import "fmt"

func main() {
    fmt.Println("Hello, World!") //This is a single-line comment
}

## ------------------| Add Dependency 
### Method I
go get github.com/gin-gonic/gin
go get -u github.com/gin-gonic/gin # update to the latest version
go get -u ./... # update all dependencies
### Method II
package main

import (
    "fmt"
    "github.com/gin-gonic/gin" // Add Dependency here!
)

func main() {
    fmt.Println("Using Gin Web Framework")
    r := gin.Default()
    r.GET("/", func(c *gin.Context) {
        c.JSON(200, gin.H{"message": "Hello, World!"})
    })
    r.Run()
}

## ------------------| Run the program 
go run main.go

## ------------------| Build the program
go build

Last updated