From fb63cbe9dfb5298eed73e220956ce4a4519e0392 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Thu, 1 Jun 2017 09:53:29 -0700 Subject: [PATCH] use strings.Join to construct options string --- data.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/data.go b/data.go index 0e2c28b..6ff581b 100644 --- a/data.go +++ b/data.go @@ -15,7 +15,6 @@ package imageproxy import ( - "bytes" "fmt" "net/http" "net/url" @@ -79,33 +78,32 @@ type Options struct { } func (o Options) String() string { - buf := new(bytes.Buffer) - fmt.Fprintf(buf, "%v%s%v", o.Width, optSizeDelimiter, o.Height) + opts := []string{fmt.Sprintf("%v%s%v", o.Width, optSizeDelimiter, o.Height)} if o.Fit { - fmt.Fprintf(buf, ",%s", optFit) + opts = append(opts, optFit) } if o.Rotate != 0 { - fmt.Fprintf(buf, ",%s%d", string(optRotatePrefix), o.Rotate) + opts = append(opts, fmt.Sprintf("%s%d", string(optRotatePrefix), o.Rotate)) } if o.FlipVertical { - fmt.Fprintf(buf, ",%s", optFlipVertical) + opts = append(opts, optFlipVertical) } if o.FlipHorizontal { - fmt.Fprintf(buf, ",%s", optFlipHorizontal) + opts = append(opts, optFlipHorizontal) } if o.Quality != 0 { - fmt.Fprintf(buf, ",%s%d", string(optQualityPrefix), o.Quality) + opts = append(opts, fmt.Sprintf("%s%d", string(optQualityPrefix), o.Quality)) } if o.Signature != "" { - fmt.Fprintf(buf, ",%s%s", string(optSignaturePrefix), o.Signature) + opts = append(opts, fmt.Sprintf("%s%s", string(optSignaturePrefix), o.Signature)) } if o.ScaleUp { - fmt.Fprintf(buf, ",%s", optScaleUp) + opts = append(opts, optScaleUp) } if o.Format != "" { - fmt.Fprintf(buf, ",%s", o.Format) + opts = append(opts, o.Format) } - return buf.String() + return strings.Join(opts, ",") } // transform returns whether o includes transformation options. Some fields