github.com/lingyao2333/mo-zero@v1.4.1/core/logx/lesswriter.go (about)

     1  package logx
     2  
     3  import "io"
     4  
     5  type lessWriter struct {
     6  	*limitedExecutor
     7  	writer io.Writer
     8  }
     9  
    10  func newLessWriter(writer io.Writer, milliseconds int) *lessWriter {
    11  	return &lessWriter{
    12  		limitedExecutor: newLimitedExecutor(milliseconds),
    13  		writer:          writer,
    14  	}
    15  }
    16  
    17  func (w *lessWriter) Write(p []byte) (n int, err error) {
    18  	w.logOrDiscard(func() {
    19  		w.writer.Write(p)
    20  	})
    21  	return len(p), nil
    22  }