forked from kernle32dll/nullable
-
Notifications
You must be signed in to change notification settings - Fork 1
/
float64.go
72 lines (58 loc) · 1.57 KB
/
float64.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Code generated by go generate; DO NOT EDIT.
// This file was generated by scripts/models/gen_nullable_types.go
package nullable
import (
"bytes"
"encoding/json"
"github.com/go-openapi/strfmt"
)
// Float64 represents a float64 that may be null or not
// present in json at all.
type Float64 struct {
Present bool // Present is true if key is present in json
Valid bool // Valid is true if value is not null and valid float64
Value float64
}
// Returns nil if not present or valid. Otherwise it will
// return a pointer to the value.
func (f *Float64) Ptr() *float64 {
if f.Present && f.Valid {
return &f.Value
}
return nil
}
// UnmarshalJSON implements json.Marshaler interface.
func (f *Float64) UnmarshalJSON(data []byte) error {
f.Present = true
if bytes.Equal(data, null) {
return nil
}
if err := json.Unmarshal(data, &f.Value); err != nil {
return err
}
f.Valid = true
return nil
}
// Validate implements runtime.Validateable interface for go-swagger generation.
func (f *Float64) Validate(formats strfmt.Registry) error {
return nil
}
// Float64Slice represents a []float64 that may be null or not
// present in json at all.
type Float64Slice struct {
Present bool // Present is true if key is present in json
Valid bool // Valid is true if value is not null
Value []float64
}
// UnmarshalJSON implements json.Marshaler interface.
func (f *Float64Slice) UnmarshalJSON(data []byte) error {
f.Present = true
if bytes.Equal(data, null) {
return nil
}
if err := json.Unmarshal(data, &f.Value); err != nil {
return err
}
f.Valid = true
return nil
}