github.com/searKing/golang/go@v1.2.117/io/io.go (about) 1 // Copyright 2020 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package io 6 7 import ( 8 "io" 9 "os" 10 ) 11 12 var _ io.Closer = CloserFunc(nil) 13 14 // Stater is the interface that wraps the basic Stat method. 15 // Stat returns the FileInfo structure describing file. 16 type Stater interface { 17 Stat() (os.FileInfo, error) 18 } 19 20 // The CloserFunc type is an adapter to allow the use of 21 // ordinary functions as io.Closer handlers. If f is a function 22 // with the appropriate signature, CloserFunc(f) is a 23 // Handler that calls f. 24 type CloserFunc func() error 25 26 // Close calls f(w, r). 27 func (f CloserFunc) Close() error { 28 if f == nil { 29 return nil 30 } 31 return f() 32 } 33 34 // CloseIf call Close() if arg implements io.Closer 35 func CloseIf(c any) error { 36 if c, ok := c.(io.Closer); ok && c != nil { 37 return c.Close() 38 } 39 return nil 40 }