×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang os.IsTimeout() Function with Examples

Golang | os.IsTimeout() Function: Here, we are going to learn about the IsTimeout() function of the os package with its usages, syntax, and examples.
Submitted by IncludeHelp, on November 25, 2021

os.IsTimeout()

In the Go language, the os package provides a platform-independent interface to operating system (Unix-like) functionality. The IsTimeout() function is an inbuilt function of the os package, it is used to check whether the given error is known to report that a timeout occurred. This function predates errors.Is.

It accepts one parameter (err error) and returns a boolean indicating whether the error is known to report that a timeout occurred.

Syntax

func IsTimeout(err error) bool

Parameters

  • err - Error

Return Value

The return type of the os.IsTimeout() function is a bool, it returns a boolean indicating whether the error is known to report that a timeout occurred.

Example

// Golang program to demonstrate the
// example of IsTimeout() function

package main

import (
	"fmt"
	"net/http"
	"os"
	"time"
)

func main() {
	client := &http.Client{
		Timeout: time.Nanosecond * 1,
	}
	_, err := client.Get("https://www.wikipedia.org/")
	fmt.Println("err:", err)
	fmt.Println("os.IsTimeout:", os.IsTimeout(err))
}

Output:

err: Get "https://www.wikipedia.org/": dial tcp: lookup www.wikipedia.org on 169.254.169.254:53: dial udp 169.254.169.254:53: connect: no route to host
os.IsTimeout: false

Golang os Package »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.