chore: initial commit
This commit is contained in:
28
internal/pkg/validator/null_int32.go
Normal file
28
internal/pkg/validator/null_int32.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package validator
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// NullInt32 Valid(false) + Set(true) = null | Valid(false) + Set(false) = nil
|
||||
type NullInt32 struct {
|
||||
Value int32
|
||||
Valid bool
|
||||
Set bool
|
||||
}
|
||||
|
||||
func (i *NullInt32) UnmarshalJSON(data []byte) error {
|
||||
i.Set = true
|
||||
|
||||
if string(data) == "null" {
|
||||
i.Valid = false
|
||||
return nil
|
||||
}
|
||||
|
||||
var temp int32
|
||||
if err := json.Unmarshal(data, &temp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i.Value = temp
|
||||
i.Valid = true
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user