forked from pagarme/pagarme-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createPhoneRequest.go
48 lines (42 loc) · 1.03 KB
/
createPhoneRequest.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
package models
import (
"encoding/json"
)
type CreatePhoneRequest struct {
CountryCode *string `json:"country_code,omitempty"`
Number *string `json:"number,omitempty"`
AreaCode *string `json:"area_code,omitempty"`
}
func (c *CreatePhoneRequest) MarshalJSON() (
[]byte,
error) {
return json.Marshal(c.toMap())
}
func (c *CreatePhoneRequest) toMap() map[string]any {
structMap := make(map[string]any)
if c.CountryCode != nil {
structMap["country_code"] = c.CountryCode
}
if c.Number != nil {
structMap["number"] = c.Number
}
if c.AreaCode != nil {
structMap["area_code"] = c.AreaCode
}
return structMap
}
func (c *CreatePhoneRequest) UnmarshalJSON(input []byte) error {
temp := &struct {
CountryCode *string `json:"country_code,omitempty"`
Number *string `json:"number,omitempty"`
AreaCode *string `json:"area_code,omitempty"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
c.CountryCode = temp.CountryCode
c.Number = temp.Number
c.AreaCode = temp.AreaCode
return nil
}