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