move the redundant writeline writeBytesLine to proxy/util/util.go

This commit is contained in:
jornshen
2021-01-19 21:09:03 +08:00
parent 73d4c245ef
commit 3783821553
3 changed files with 114 additions and 130 deletions

View File

@@ -17,6 +17,7 @@ limitations under the License.
package util
import (
"bytes"
"context"
"errors"
"fmt"
@@ -441,3 +442,22 @@ func GetClusterIPByFamily(ipFamily v1.IPFamily, service *v1.Service) string {
return ""
}
// WriteLine join all words with spaces, terminate with newline and write to buff.
func WriteLine(buf *bytes.Buffer, words ...string) {
// We avoid strings.Join for performance reasons.
for i := range words {
buf.WriteString(words[i])
if i < len(words)-1 {
buf.WriteByte(' ')
} else {
buf.WriteByte('\n')
}
}
}
// WriteBytesLine write bytes to buffer, terminate with newline
func WriteBytesLine(buf *bytes.Buffer, bytes []byte) {
buf.Write(bytes)
buf.WriteByte('\n')
}