github.com/nikandfor/tlog@v0.21.5-0.20231108111739-3ef89426a96d/tlio/string.go (about)

     1  package tlio
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  func (w MultiWriter) String() string {
     9  	var b strings.Builder
    10  
    11  	_, _ = b.WriteString("MultiWriter{")
    12  
    13  	for i, w := range w {
    14  		if i != 0 {
    15  			_, _ = b.WriteString(" ")
    16  		}
    17  
    18  		writeWriter(&b, w)
    19  	}
    20  
    21  	_, _ = b.WriteString("}")
    22  
    23  	return b.String()
    24  }
    25  
    26  func (w WriteCloser) String() string {
    27  	var b strings.Builder
    28  
    29  	_, _ = b.WriteString("WriteCloser{")
    30  
    31  	_, _ = b.WriteString("Writer:")
    32  	writeWriter(&b, w.Writer)
    33  
    34  	_, _ = b.WriteString(" Closer:")
    35  	writeWriter(&b, w.Closer)
    36  
    37  	_, _ = b.WriteString("}")
    38  
    39  	return b.String()
    40  }
    41  
    42  func writeWriter(b *strings.Builder, o interface{}) {
    43  	if s, ok := o.(fmt.Stringer); ok {
    44  		_, _ = b.WriteString(s.String())
    45  	} else {
    46  		_, _ = fmt.Fprintf(b, "%T", o)
    47  	}
    48  }