1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-09-16 09:36:18 +02:00

Properly marshal imageType, resizingType and gravityType

This commit is contained in:
DarthSim
2019-10-10 20:55:51 +06:00
parent cc394501df
commit 7c13bdad11
2 changed files with 27 additions and 0 deletions

View File

@@ -78,6 +78,15 @@ func (it imageType) String() string {
return ""
}
func (it imageType) MarshalJSON() ([]byte, error) {
for k, v := range imageTypes {
if v == it {
return []byte(fmt.Sprintf("%q", k)), nil
}
}
return []byte("null"), nil
}
func (it imageType) Mime() string {
if mime, ok := mimes[it]; ok {
return mime

View File

@@ -152,6 +152,15 @@ func (gt gravityType) String() string {
return ""
}
func (gt gravityType) MarshalJSON() ([]byte, error) {
for k, v := range gravityTypes {
if v == gt {
return []byte(fmt.Sprintf("%q", k)), nil
}
}
return []byte("null"), nil
}
func (rt resizeType) String() string {
for k, v := range resizeTypes {
if v == rt {
@@ -161,6 +170,15 @@ func (rt resizeType) String() string {
return ""
}
func (rt resizeType) MarshalJSON() ([]byte, error) {
for k, v := range resizeTypes {
if v == rt {
return []byte(fmt.Sprintf("%q", k)), nil
}
}
return []byte("null"), nil
}
var (
_newProcessingOptions processingOptions
newProcessingOptionsOnce sync.Once