Golang vs Python: The Ultimate Battle in DevOps

In the world of DevOps, two programming languages are often pitted against each other: Golang and Python. Both languages have their own strengths and weaknesses, and choosing the right one for your DevOps needs can be a tough decision. In this blog post, we will take a closer look at Golang and Python, and compare their capabilities in the DevOps landscape. Golang Golang is a language that has gained immense popularity in recent years, especially in the field of DevOps....

May 27, 2023 · 9 min · 1711 words · AO

How to Create a Password Generator in Golang

Introduction In today’s digital age, password security is more important than ever before. Hackers can easily guess weak passwords, leading to identity theft and other cybersecurity breaches. To ensure our online safety, we need to use strong and secure passwords that are difficult to guess. A good password generator can help us create random and strong passwords. In this blog post, we’ll discuss how to create a password generator in Golang....

April 2, 2023 · 2 min · 298 words · AO

How to Convert Time to String in Golang

If you need to convert Time to a String in Go, then you can do one of the following: Option 1 – Using time.Now package main import ( "fmt" "time" ) func main() { currentTime := time.Now() fmt.Println("Time: ", currentTime.String()) } Option 2 – Using time.Time.String() package main import ( "fmt" "time" ) func main() { Time := time.Date(2022, 03, 28, 03, 50, 16, 0, time.UTC) t := Time.String() fmt.Printf("Time without the nano seconds: %v\n", t) }

October 6, 2022 · 1 min · 77 words · Andrew

How to Perform a Deep Copy in Golang

To perform a Deep Copy in Go, you can use a struct type as follows: Deep Copying using a struct in Go package main import ( "fmt" ) type Dog struct { age int name string friends []string } func main() { john := Dog{1, "Harry", []string{"Steve", "Matt", "Sarah"}} jack := john jack.friends = make([]string, len(john.friends)) copy(jack.friends, harry.friends) jack.friends = append(jay.friends, "Fred") fmt.Println(john) fmt.Println(jack) }

October 5, 2022 · 1 min · 65 words · Andrew

How to Return Lambda Functions in Golang

Go doesn’t typically have Lambda Expressions, but synonymous to Lambdas, or Closures if Anonymous Functions for Go. How to return a value from an Anonymous Function in Go package main import "fmt" func main() { var sum = func(n1, n2 int) int { sum := n1 + n2 return sum } result := sum(5, 3) fmt.Println("Sum is:", result) } How to return an Area from an Anonymous Function in Go package main import "fmt" var ( area = func(l int, b int) int { return l * b } ) func main() { fmt....

October 4, 2022 · 1 min · 96 words · Andrew

How to Create an Empty Slice in Golang

If you would like to create an empty slice in Go, then you can do the following: Option 1 – Initialize an Empty Slice in Go package main import "fmt" func main() { b := []string{} fmt.Println(b == nil) } Option 2 – Using make() package main import "fmt" func main() { c := make([]string, 0) fmt.Println(c == nil) }

October 3, 2022 · 1 min · 60 words · Andrew

[Solved] dial tcp: lookup proxy.golang.org: i/o timeout

If you get a timeout when trying to install go dependencies, the error may look something like this: $ go get github.com/aws/aws-sdk-go/aws go: module github.com/aws/aws-sdk-go/aws: Get "https://proxy.golang.org/github.com/aws/aws-sdk-go/aws/@v/list": dial tcp: lookup proxy.golang.org: i/o timeout How to Solve the Timeout Issue when installing Go Deps export GOPROXY=direct Then re-run your go get command.

September 25, 2022 · 1 min · 51 words · Andrew

How to Execute Linux Commands in Golang

If you want to execute linux commands in Golang, then you can use exec.Command: cmd := exec.Command("echo", "hello world") res, _ := cmd.CombinedOutput() fmt.Println(string(res))

July 4, 2022 · 1 min · 24 words · Andrew

How to Check for Prime Numbers using Golang

If you need to check for Prime Numbers in Golang, then you can use the following method: const n = 1212121 if big.NewInt(n).ProbablyPrime(0) { fmt.Println(n, "is prime") } else { fmt.Println(n, "is not prime") }

July 3, 2022 · 1 min · 35 words · Andrew

How to Raise a Number to a Power in Golang

If you need to raise a number to a power in Golang, then you can use the math.Pow function: package main import ( "math" ) func main() { var exponent, base float64 output := math.Pow(base, exponent) }

July 2, 2022 · 1 min · 37 words · Andrew