mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 22:05:43 +01:00
30 lines
463 B
Go
30 lines
463 B
Go
package graphql
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
)
|
|
|
|
func MarshalBoolean(b bool) Marshaler {
|
|
return WriterFunc(func(w io.Writer) {
|
|
if b {
|
|
w.Write(trueLit)
|
|
} else {
|
|
w.Write(falseLit)
|
|
}
|
|
})
|
|
}
|
|
|
|
func UnmarshalBoolean(v interface{}) (bool, error) {
|
|
switch v := v.(type) {
|
|
case string:
|
|
return strings.ToLower(v) == "true", nil
|
|
case int:
|
|
return v != 0, nil
|
|
case bool:
|
|
return v, nil
|
|
default:
|
|
return false, fmt.Errorf("%T is not a bool", v)
|
|
}
|
|
}
|