Documentation ¶
Index ¶
- Variables
- func Close(closers ...io.Closer) error
- func CloseSingle(closer io.Closer) error
- func CountLines(r io.Reader) (count int, err error)
- func CountLines1(r io.Reader) (int, error)
- func MultiReader(readers ...io.Reader) io.Reader
- func MultiWriteCloser(writeClosers ...io.WriteCloser) io.WriteCloser
- func MultiWriter(writers ...io.Writer) io.Writer
- func NewDailyWriteCloser(filePath string, options ...LumberJackOption) (io.WriteCloser, error)
- func NewFileReader(filePath string) (*os.File, error)
- func NewLumberJackWriteCloser(filePath string, maxSize int64, options ...LumberJackOption) (*lumberjack.Roller, error)
- func NewReader(s []byte) io.Reader
- func NewReaderFromString(str string) io.Reader
- func NewRotatableWriteCloserWithSpec(filePath string, spec string, options ...LumberJackOption) (io.WriteCloser, error)
- func NopCloserToReadSeeker(readSeeker io.ReadSeeker) io.ReadSeekCloser
- func ReadFromReader(reader io.Reader) ([]byte, error)
- func ReadStringFromReader(reader io.Reader) (string, error)
- func SeekToStart(seeker io.Seeker) (int64, error)
- func ToBufioReader(reader io.Reader) *bufio.Reader
- func TryToClose(objs ...any) error
- type DailyWriteCloser
- type LumberJackOption
Constants ¶
This section is empty.
Variables ¶
var ( // NewReadWriter bytes.Buffer 结构体 实现了 io.ReadWriter 接口 /* @param s 可以为nil */ NewReadWriter func(s []byte) *bytes.Buffer = bytes.NewBuffer // NewReadWriterFromString bytes.Buffer 结构体 实现了 io.ReadWriter 接口 /* @param str 可以为"" */ NewReadWriterFromString func(str string) *bytes.Buffer = bytes.NewBufferString )
var NopCloser func(reader io.Reader) io.ReadCloser = io.NopCloser
NopCloser
PS: 返回值调用Close()将什么都不会做,直接返回nil.
Functions ¶
func Close ¶
Close
PS: 就算循环过程中返回了非nil的error,也要继续向下循环(尽可能多地关闭).
@param closers (1) 可以为nil(即不传参);(2) 其中可以有nil @return 发生error的话,返回第一个
func CloseSingle ¶
func MultiWriteCloser ¶
func MultiWriteCloser(writeClosers ...io.WriteCloser) io.WriteCloser
MultiWriteCloser
PS: 参考了 io.MultiWriter().
func NewDailyWriteCloser ¶
func NewDailyWriteCloser(filePath string, options ...LumberJackOption) (io.WriteCloser, error)
NewDailyWriteCloser 每天凌晨0点,执行Rotate().
@param options 可选配置,参考 NewLumberJackWriteCloser()
func NewFileReader ¶
NewFileReader
!!!:要在外部手动调用 *os.File 的Close方法.
@return os.File 结构体 实现了 io.Reader 接口
func NewLumberJackWriteCloser ¶
func NewLumberJackWriteCloser(filePath string, maxSize int64, options ...LumberJackOption) (*lumberjack.Roller, error)
NewLumberJackWriteCloser 可rotate(依据传参maxSize)的io.WriteCloser.
PS: (1) 如果 当前目标文件 被人为删了,会丢失部分输出直至再次调用Rotate(). (2) 可以同时配置 MaxBackups 和 MaxAge.
@param maxSize unit: byte @param options 可选配置: WithCompress() [默认: 不压缩] 是否压缩被rotate的文件? WithMaxBackups() [默认: 保留所有旧日志] 旧日志保存的最多数量 WithMaxAge() [默认: 保留所有旧日志] 旧日志保存的最长时间 WithLocalTime() [默认: true] true: 使用本地时间; false: 使用UTC时间
func NewReaderFromString ¶
func NewRotatableWriteCloserWithSpec ¶
func NewRotatableWriteCloserWithSpec(filePath string, spec string, options ...LumberJackOption) (io.WriteCloser, error)
NewRotatableWriteCloserWithSpec 满足条件(spec),执行Rotate().
PS: (1) 可能存在情况,Rotate()后,生成的旧日志文件大小为0B.
func NopCloserToReadSeeker ¶
func NopCloserToReadSeeker(readSeeker io.ReadSeeker) io.ReadSeekCloser
NopCloserToReadSeeker 给 io.ReadSeeker 实例加上Close()(虽然这个Close()什么都不做).
func ReadFromReader ¶
ReadFromReader 读取io.Reader的内容(io.Reader => []byte)
func ReadStringFromReader ¶
ReadStringFromReader 读取io.Reader的内容(io.Reader => string)
func ToBufioReader ¶
ToBufioReader io.Reader 接口 => *bufio.Reader
作用: 可以调用 bufio.Reader 结构体的方法(因为 io.Reader 接口就一个Read方法).
func TryToClose ¶
TryToClose 尝试关闭(如果实现了io.Closer接口的话).
@param writers (1) 可以为nil(即不传参)
(2) 其中可以有nil
@return 发生error的话,返回第一个
Types ¶
type DailyWriteCloser ¶
type DailyWriteCloser struct {
// contains filtered or unexported fields
}
func (*DailyWriteCloser) Close ¶
func (dwc *DailyWriteCloser) Close() error
type LumberJackOption ¶
type LumberJackOption func(opts *lumberjackOptions)
func WithCompress ¶
func WithCompress(compress bool) LumberJackOption
func WithLocalTime ¶
func WithLocalTime(localTime bool) LumberJackOption
func WithMaxAge ¶
func WithMaxAge(maxAge time.Duration) LumberJackOption
func WithMaxBackups ¶
func WithMaxBackups(maxBackups int) LumberJackOption