From a025d55d81c297acf591853c7e7e2a1f2a5fce85 Mon Sep 17 00:00:00 2001 From: Saxon Date: Tue, 30 Apr 2019 21:41:46 +0930 Subject: [PATCH] protocol/rtsp: using Fprintf with strings.Builder in Request.String() and Response.String() --- protocol/rtsp/rtsp.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/protocol/rtsp/rtsp.go b/protocol/rtsp/rtsp.go index e46fdeb5..7f032967 100644 --- a/protocol/rtsp/rtsp.go +++ b/protocol/rtsp/rtsp.go @@ -81,10 +81,10 @@ func (r *Request) Write(w io.Writer) error { // String returns a formatted string of the Request. func (r Request) String() string { var b strings.Builder - b.WriteString(r.Method + " " + r.URL.String() + " " + r.Proto + "/" + strconv.Itoa(r.ProtoMajor) + "." + strconv.Itoa(r.ProtoMinor) + "\r\n") + fmt.Fprintf(&b, "%s %s %s/%d.%d\r\n", r.Method, r.URL.String(), r.Proto, r.ProtoMajor, r.ProtoMinor) for k, v := range r.Header { for _, v := range v { - b.WriteString(k + ": " + v + "\r\n") + fmt.Fprintf(&b, "%s: %s\r\n", k, v) } } b.WriteString("\r\n") @@ -109,10 +109,10 @@ type Response struct { // String returns a formatted string of the Response. func (r Response) String() string { var b strings.Builder - b.WriteString(r.Proto + "/" + strconv.Itoa(r.ProtoMajor) + "." + strconv.Itoa(r.ProtoMinor) + " " + strconv.Itoa(r.StatusCode) + "\n") + fmt.Fprintf(&b, "%s/%d.%d %d\n", r.Proto, r.ProtoMajor, r.ProtoMinor, r.StatusCode) for k, v := range r.Header { for _, v := range v { - b.WriteString(k + ": " + v + "\n") + fmt.Fprintf(&b, "%s: %s", k, v) } } return b.String()