add mimetype to service response

This commit is contained in:
David Christofas
2020-03-18 11:13:09 +01:00
parent 06151de3f4
commit 024e4661e2
4 changed files with 42 additions and 18 deletions
+12
View File
@@ -14,6 +14,8 @@ type Encoder interface {
Encode(io.Writer, image.Image) error
// Types returns the formats suffixes.
Types() []string
// MimeType returns the mimetype used by the encoder.
MimeType() string
}
// PngEncoder encodes to png
@@ -29,6 +31,11 @@ func (e PngEncoder) Types() []string {
return []string{"png"}
}
// MimeType returns the mimetype for png files.
func (e PngEncoder) MimeType() string {
return "image/png"
}
// JpegEncoder encodes to jpg.
type JpegEncoder struct{}
@@ -42,6 +49,11 @@ func (e JpegEncoder) Types() []string {
return []string{"jpeg", "jpg"}
}
// MimeType returns the mimetype for jpg files.
func (e JpegEncoder) MimeType() string {
return "image/jpeg"
}
// EncoderForType returns the encoder for a given file type
// or nil if the type is not supported.
func EncoderForType(fileType string) Encoder {