add issue tasks.

This commit is contained in:
2020-05-10 20:50:18 +02:00
parent 3039dc1879
commit 47d8a027da
21 changed files with 598 additions and 15 deletions
+30
View File
@@ -0,0 +1,30 @@
package scalars
import (
"fmt"
"github.com/99designs/gqlgen/graphql"
"io"
"strconv"
"time"
)
func MarshalDuration(d time.Duration) graphql.Marshaler {
return graphql.WriterFunc(func(w io.Writer) {
_, _ = w.Write([]byte(strconv.Itoa(int(d.Milliseconds()))))
})
}
func UnmarshalDuration(v interface{}) (time.Duration, error) {
switch v := v.(type) {
case string:
return time.ParseDuration(v)
case int:
return time.Millisecond * time.Duration(v), nil
case int64:
return time.Millisecond * time.Duration(v), nil
case float64:
return time.Millisecond * time.Duration(v), nil
default:
return 0, fmt.Errorf("%T is not a bool", v)
}
}