forked from pagarme/pagarme-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getPhoneResponse.go
50 lines (43 loc) · 1.13 KB
/
getPhoneResponse.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
package models
import (
"encoding/json"
"github.com/apimatic/go-core-runtime/types"
)
type GetPhoneResponse struct {
CountryCode types.Optional[string] `json:"country_code"`
Number types.Optional[string] `json:"number"`
AreaCode types.Optional[string] `json:"area_code"`
}
func (g *GetPhoneResponse) MarshalJSON() (
[]byte,
error) {
return json.Marshal(g.toMap())
}
func (g *GetPhoneResponse) toMap() map[string]any {
structMap := make(map[string]any)
if g.CountryCode.IsValueSet() {
structMap["country_code"] = g.CountryCode.Value()
}
if g.Number.IsValueSet() {
structMap["number"] = g.Number.Value()
}
if g.AreaCode.IsValueSet() {
structMap["area_code"] = g.AreaCode.Value()
}
return structMap
}
func (g *GetPhoneResponse) UnmarshalJSON(input []byte) error {
temp := &struct {
CountryCode types.Optional[string] `json:"country_code"`
Number types.Optional[string] `json:"number"`
AreaCode types.Optional[string] `json:"area_code"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
g.CountryCode = temp.CountryCode
g.Number = temp.Number
g.AreaCode = temp.AreaCode
return nil
}