forked from pagarme/pagarme-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createIncrementRequest.go
55 lines (49 loc) · 1.33 KB
/
createIncrementRequest.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
package models
import (
"encoding/json"
)
// Request for creating a new increment
type CreateIncrementRequest struct {
Value float64 `json:"value"`
IncrementType string `json:"increment_type"`
ItemId string `json:"item_id"`
Cycles *int `json:"cycles,omitempty"`
Description *string `json:"description,omitempty"`
}
func (c *CreateIncrementRequest) MarshalJSON() (
[]byte,
error) {
return json.Marshal(c.toMap())
}
func (c *CreateIncrementRequest) toMap() map[string]any {
structMap := make(map[string]any)
structMap["value"] = c.Value
structMap["increment_type"] = c.IncrementType
structMap["item_id"] = c.ItemId
if c.Cycles != nil {
structMap["cycles"] = c.Cycles
}
if c.Description != nil {
structMap["description"] = c.Description
}
return structMap
}
func (c *CreateIncrementRequest) UnmarshalJSON(input []byte) error {
temp := &struct {
Value float64 `json:"value"`
IncrementType string `json:"increment_type"`
ItemId string `json:"item_id"`
Cycles *int `json:"cycles,omitempty"`
Description *string `json:"description,omitempty"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
c.Value = temp.Value
c.IncrementType = temp.IncrementType
c.ItemId = temp.ItemId
c.Cycles = temp.Cycles
c.Description = temp.Description
return nil
}