go Pause execution for several seconds

package main

import (
    "fmt"
    "time"
)

func main() {
    fmt.Println("Before sleeping")
    time.Sleep(5 * time.Second)
    fmt.Println("After sleeping")
}

This Go program demonstrates the usage of the time.Sleep() function to pause execution for a specified duration.

  1. Import necessary packages: The fmt package is used for formatted I/O, and the time package provides functionality related to time.

  2. Define the main() function as the entry point of the program.

  3. Print "Before sleeping" using fmt.Println() to indicate the start of the sleep period.

  4. Use time.Sleep() to pause the program execution. 5 * time.Second specifies the duration for which the program will sleep (in this case, 5 seconds).

  5. Print "After sleeping" using fmt.Println() after the sleep duration elapses to indicate the end of the sleep period.