-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: anqurvanillapy <[email protected]>
- Loading branch information
1 parent
5224a38
commit f291eef
Showing
4 changed files
with
72 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package types | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/alecthomas/units" | ||
"github.com/invopop/jsonschema" | ||
) | ||
|
||
type Duration struct{ Dur time.Duration } | ||
|
||
func (Duration) JSONSchema() *jsonschema.Schema { | ||
return &jsonschema.Schema{ | ||
Type: "string", | ||
Title: "Duration", | ||
Description: "Go-compatible duration", | ||
} | ||
} | ||
|
||
func (d Duration) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
var s string | ||
if err := unmarshal(&s); err != nil { | ||
return err | ||
} | ||
dur, err := time.ParseDuration(s) | ||
if err != nil { | ||
return err | ||
} | ||
d.Dur = dur | ||
return nil | ||
} | ||
|
||
type Size struct{ Size units.Base2Bytes } | ||
|
||
func (Size) JSONSchema() *jsonschema.Schema { | ||
return &jsonschema.Schema{ | ||
Type: "string", | ||
Title: "Size", | ||
Description: "Go-compatible data size", | ||
} | ||
} | ||
|
||
func (s Size) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
var r string | ||
if err := unmarshal(&r); err != nil { | ||
return err | ||
} | ||
size, err := units.ParseBase2Bytes(r) | ||
if err != nil { | ||
return err | ||
} | ||
s.Size = size | ||
return nil | ||
} |