github.com/sujit-baniya/log@v1.0.73/fqdn/errors.go (about)

     1  package fqdn
     2  
     3  import "fmt"
     4  
     5  // Error for cases when os.Hostname() fails.
     6  var ErrHostnameFailed = errHostnameFailed{}
     7  
     8  // Error for cases when we could not found fqdn for whatever reason.
     9  var ErrFqdnNotFound = errFqdnNotFound{}
    10  
    11  type errHostnameFailed struct {
    12  	cause error
    13  }
    14  
    15  func (e errHostnameFailed) Error() string {
    16  	return fmt.Sprintf("could not get hostname: %v", e.cause)
    17  }
    18  
    19  func (e errHostnameFailed) Unwrap() error {
    20  	return e.cause
    21  }
    22  
    23  func (e errHostnameFailed) Is(target error) bool {
    24  	switch target.(type) {
    25  	case errHostnameFailed:
    26  		return true
    27  	default:
    28  		return false
    29  	}
    30  }
    31  
    32  type errFqdnNotFound struct {
    33  	cause error
    34  }
    35  
    36  func (e errFqdnNotFound) Error() string {
    37  	return fmt.Sprintf("fqdn hostname not found: %v", e.cause)
    38  }
    39  
    40  func (e errFqdnNotFound) Unwrap() error {
    41  	return e.cause
    42  }
    43  
    44  func (e errFqdnNotFound) Is(target error) bool {
    45  	switch target.(type) {
    46  	case errFqdnNotFound:
    47  		return true
    48  	default:
    49  		return false
    50  	}
    51  }