gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

writer.go (395B)


      1 package sse
      2 
      3 import "io"
      4 
      5 type stringWriter interface {
      6 	io.Writer
      7 	WriteString(string) (int, error)
      8 }
      9 
     10 type stringWrapper struct {
     11 	io.Writer
     12 }
     13 
     14 func (w stringWrapper) WriteString(str string) (int, error) {
     15 	return w.Writer.Write([]byte(str))
     16 }
     17 
     18 func checkWriter(writer io.Writer) stringWriter {
     19 	if w, ok := writer.(stringWriter); ok {
     20 		return w
     21 	} else {
     22 		return stringWrapper{writer}
     23 	}
     24 }