Go Programming Language¶
Go Language¶
GOROOT="/usr/local/go"
GOPATH="/Users/senthilx/go"
GOPRIVATE=""
GOPROXY="direct"
Go code organization
I set this up in bash profile.
export GOROOT="/usr/local/go"
export GOPATH="/home/senthilx/go"
export GOPRIVATE=""
export GOPROXY="direct"
go install golang.org/x/tools/cmd/goimports@latest
Installed vim-go as the only plugin to work with the default vim. Made sure my ide is working without red lines.
How to use slices in go?
var slice := []int
slice = append(slice, 10)
Go Proxy¶
go env -w GOPROXY=direct
Install the latest version¶
go install golang.org/dl/go1.19.1@latest
go1.19.1 download
echo "export PATH=~/sdk/go1.19.1/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
go version
How to test go code¶
Write it in play.golang.org
Use this template
package main
import (
"log"
"time"
)
func main() {
date := "7/25/2019 13:45:00" # "7/25/2019 13:45:00"
timeT, err := time.Parse("1/2/2006 15:04:05", date)
if err != nil {
log.Fatalf("Error parsing: %v", err)
}
log.Printf("Got: %v", timeT)
}
Modify and Test
Advantages sharable, and no need to create cruft.
Example play link - https://play.golang.org/p/73Gt3O1Ok-1