😴 Sleep function in Go

April 12, 2021
introduction goroutine time

To pause the execution of a current program in Go, you just need to use Sleep() function defined in time package. As an argument, this function takes a variable of type time.Duration, which is the amount of time the program execution should be stopped for. It can be expressed as a number multiplied by a unit constant, for example 3*time.Second means that the execution will be stopped for 3 seconds. Available units are:

package main

import (
    "fmt"
    "time"
)

func main() {
    fmt.Println("before Sleep()")

    time.Sleep(3 * time.Second)

    fmt.Println("waking up after Sleep()")
}

✒️ Write to a CSV file in Go

Learn how to write data to a CSV or TSV file
introduction file

🙌 Case-insensitive string comparison in Go

Learn how to compare strings in a case-insensitive manner
introduction strings

🏁 Check if a string starts with a substring in Go

Learn how to use strings.HasPrefix() function
introduction strings