Posts

Showing posts from September, 2019

GO lang to print colored output

package main import ( "fmt" ) func Red(format string, args ...interface{}) { fmt.Printf("\033[31m"+format+"\033[0m", args...) } func Green(format string, args ...interface{}) { fmt.Printf("\033[32m"+format+"\033[0m", args...) } func Yellow(format string, args ...interface{}) { fmt.Printf("\033[33m"+format+"\033[0m", args...) } func Blue(format string, args ...interface{}) { fmt.Printf("\033[34m"+format+"\033[0m", args...) } func Magenta(format string, args ...interface{}) { fmt.Printf("\033[35m"+format+"\033[0m", args...) } func Cyan(format string, args ...interface{}) { fmt.Printf("\033[36m"+format+"\033[0m", args...) } func main() { // Set the foreground color to red Red("Hello, world!\n") Yellow("Hello, world!\n") Green("Hello, world!\n") Magenta("Hello, world!\n") Cyan("Hello, world!\...

Installing golang compiler in linux machine

Download the Go 1.12.1 binary archive suitable for your operating system from the official Go website ( https://golang.org/dl/ ). wget https://dl.google.com/go/go1.12.1.linux-amd64.tar.gz Extract the downloaded archive to the /usr/local directory: sudo tar -C /usr/local -xzf go1.12.1.linux-amd64.tar.gz Add the Go binary directory to your system’s PATH environment variable by editing your shell profile file (e.g. ~/.bashrc or ~/.zshrc) and adding the following lines: export PATH=$PATH:/usr/local/go/bin Reload your shell profile to apply the changes: source ~/.bashrc go version output: go version go1.12.1 linux/amd64 lets print HelloWorld! from go package main import "fmt" func main() { fmt.Printf("HelloWorld!") } Output: HelloWorld! < Blog Archive Archive of all previous blog posts > Blog Archive Archive of all previous blog posts