404710eaa4
BenchmarkResponseWriter 1239 1304 +5.25% BenchmarkFullSSE 1469 915 -37.71% BenchmarkNoRetrySSE 1187 785 -33.87% BenchmarkSimpleSSE 961 687 -28.51% benchmark old allocs new allocs delta BenchmarkResponseWriter 9 9 +0.00% BenchmarkFullSSE 12 3 -75.00% BenchmarkNoRetrySSE 11 2 -81.82% BenchmarkSimpleSSE 8 2 -75.00% benchmark old bytes new bytes delta BenchmarkResponseWriter 442 442 +0.00% BenchmarkFullSSE 462 320 -30.74% BenchmarkNoRetrySSE 473 337 -28.75% BenchmarkSimpleSSE 426 314 -26.29%
25 lines
395 B
Go
25 lines
395 B
Go
package sse
|
|
|
|
import "io"
|
|
|
|
type stringWriter interface {
|
|
io.Writer
|
|
WriteString(string) (int, error)
|
|
}
|
|
|
|
type stringWrapper struct {
|
|
io.Writer
|
|
}
|
|
|
|
func (w stringWrapper) WriteString(str string) (int, error) {
|
|
return w.Writer.Write([]byte(str))
|
|
}
|
|
|
|
func checkWriter(writer io.Writer) stringWriter {
|
|
if w, ok := writer.(stringWriter); ok {
|
|
return w
|
|
} else {
|
|
return stringWrapper{writer}
|
|
}
|
|
}
|