github.com/argoproj/argo-cd@v1.8.7/util/io/closer.go (about)

     1  package io
     2  
     3  import log "github.com/sirupsen/logrus"
     4  
     5  var (
     6  	NopCloser = NewCloser(func() error {
     7  		return nil
     8  	})
     9  )
    10  
    11  type Closer interface {
    12  	Close() error
    13  }
    14  
    15  type inlineCloser struct {
    16  	close func() error
    17  }
    18  
    19  func (c *inlineCloser) Close() error {
    20  	return c.close()
    21  }
    22  
    23  func NewCloser(close func() error) Closer {
    24  	return &inlineCloser{close: close}
    25  }
    26  
    27  // Close is a convenience function to close a object that has a Close() method, ignoring any errors
    28  // Used to satisfy errcheck lint
    29  func Close(c Closer) {
    30  	if err := c.Close(); err != nil {
    31  		log.Warnf("failed to close %v: %v", c, err)
    32  	}
    33  }