From 2132f032fe8a1abaf33297e74220dc6ab6ce40ed Mon Sep 17 00:00:00 2001 From: Paul Scott Date: Mon, 7 Nov 2022 11:00:18 +0000 Subject: [PATCH] null.{B,F,I,S,T} shorthand constructors. --- bool.go | 5 +++++ float.go | 5 +++++ int.go | 5 +++++ string.go | 10 ++++++++++ time.go | 5 +++++ 5 files changed, 30 insertions(+) diff --git a/bool.go b/bool.go index 6471149..441d403 100644 --- a/bool.go +++ b/bool.go @@ -34,6 +34,11 @@ func NewBool(b bool, valid bool) Bool { } } +// B creates a new Bool that will always be valid. +func B(b bool) Bool { + return BoolFrom(b) +} + // BoolFrom creates a new Bool that will always be valid. func BoolFrom(b bool) Bool { return NewBool(b, true) diff --git a/float.go b/float.go index 358876f..09bb927 100644 --- a/float.go +++ b/float.go @@ -31,6 +31,11 @@ func NewFloat(f float64, valid bool) Float { } } +// F creates a new Float that will always be valid. +func F(f float64) Float { + return FloatFrom(f) +} + // FloatFrom creates a new Float that will always be valid. func FloatFrom(f float64) Float { return NewFloat(f, true) diff --git a/int.go b/int.go index 1af2a83..5ebfd0f 100644 --- a/int.go +++ b/int.go @@ -29,6 +29,11 @@ func NewInt(i int64, valid bool) Int { } } +// I creates a new Int that will always be valid. +func I(i int64) Int { + return IntFrom(i) +} + // IntFrom creates a new Int that will always be valid. func IntFrom(i int64) Int { return NewInt(i, true) diff --git a/string.go b/string.go index d7d7f0f..34d93a9 100644 --- a/string.go +++ b/string.go @@ -20,6 +20,16 @@ type String struct { sql.NullString } +// S creates a new String that will never be blank. +func S(s string) String { + return StringFrom(s) +} + +// ZS creates a new String that is valid if s is not zero. +func ZS(s string) String { + return NewString(s, s != "") +} + // StringFrom creates a new String that will never be blank. func StringFrom(s string) String { return NewString(s, true) diff --git a/time.go b/time.go index 520f4ae..468eb2d 100644 --- a/time.go +++ b/time.go @@ -36,6 +36,11 @@ func NewTime(t time.Time, valid bool) Time { } } +// T creates a new Time that will always be valid. +func T(t time.Time) Time { + return TimeFrom(t) +} + // TimeFrom creates a new Time that will always be valid. func TimeFrom(t time.Time) Time { return NewTime(t, true)