-
Notifications
You must be signed in to change notification settings - Fork 4
/
optional.go
49 lines (41 loc) · 1.14 KB
/
optional.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// This file was auto-generated by Fern from our API Definition.
package api
import (
"time"
core "github.com/hookdeck/hookdeck-go-sdk/core"
)
// Optional initializes an optional field.
func Optional[T any](value T) *core.Optional[T] {
return &core.Optional[T]{
Value: value,
}
}
// NewDateFromOptional returns a new *DateTime from the given optional.
func NewDateFromOptional(optional *core.Optional[time.Time]) *core.Date {
if optional == nil {
return nil
}
return core.NewDate(optional.Value)
}
// NewDateTimeFromOptional returns a new *DateTime from the given optional.
func NewDateTimeFromOptional(optional *core.Optional[time.Time]) *core.DateTime {
if optional == nil {
return nil
}
return core.NewDateTime(optional.Value)
}
// Null initializes an optional field that will be sent as
// an explicit null value.
func Null[T any]() *core.Optional[T] {
return &core.Optional[T]{
Null: true,
}
}
// OptionalOrNull initializes an optional field, setting the value
// to an explicit null if the value is nil.
func OptionalOrNull[T any](value *T) *core.Optional[T] {
if value == nil {
return Null[T]()
}
return Optional(*value)
}