0
Fork 0
mirror of https://github.com/willnorris/imageproxy.git synced 2025-03-11 02:19:14 -05:00

use strings.Join to construct options string

This commit is contained in:
Will Norris 2017-06-01 09:53:29 -07:00
parent a85bfef357
commit fb63cbe9df

22
data.go
View file

@ -15,7 +15,6 @@
package imageproxy package imageproxy
import ( import (
"bytes"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
@ -79,33 +78,32 @@ type Options struct {
} }
func (o Options) String() string { func (o Options) String() string {
buf := new(bytes.Buffer) opts := []string{fmt.Sprintf("%v%s%v", o.Width, optSizeDelimiter, o.Height)}
fmt.Fprintf(buf, "%v%s%v", o.Width, optSizeDelimiter, o.Height)
if o.Fit { if o.Fit {
fmt.Fprintf(buf, ",%s", optFit) opts = append(opts, optFit)
} }
if o.Rotate != 0 { 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 { if o.FlipVertical {
fmt.Fprintf(buf, ",%s", optFlipVertical) opts = append(opts, optFlipVertical)
} }
if o.FlipHorizontal { if o.FlipHorizontal {
fmt.Fprintf(buf, ",%s", optFlipHorizontal) opts = append(opts, optFlipHorizontal)
} }
if o.Quality != 0 { 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 != "" { 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 { if o.ScaleUp {
fmt.Fprintf(buf, ",%s", optScaleUp) opts = append(opts, optScaleUp)
} }
if o.Format != "" { 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 // transform returns whether o includes transformation options. Some fields