writer.go 395 B

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