Skip to content

Commit

Permalink
refactor: simplify with strconv.FormatBool
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed May 24, 2024
1 parent a9965fb commit 7e227d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
7 changes: 3 additions & 4 deletions graphql/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package graphql
import (
"fmt"
"io"
"strconv"
"strings"
)

func MarshalBoolean(b bool) Marshaler {
if b {
return WriterFunc(func(w io.Writer) { w.Write(trueLit) })
}
return WriterFunc(func(w io.Writer) { w.Write(falseLit) })
str := strconv.FormatBool(b)
return WriterFunc(func(w io.Writer) { w.Write([]byte(str)) })
}

func UnmarshalBoolean(v any) (bool, error) {
Expand Down
6 changes: 1 addition & 5 deletions graphql/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ func UnmarshalString(v any) (string, error) {
case json.Number:
return string(v), nil
case bool:
if v {
return "true", nil
} else {
return "false", nil
}
return strconv.FormatBool(v), nil
case nil:
return "null", nil
default:
Expand Down

0 comments on commit 7e227d5

Please sign in to comment.