-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
jsonapi.go
43 lines (34 loc) · 927 Bytes
/
jsonapi.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
package presenters
import (
"fmt"
"strconv"
)
// JAID represents a JSON API ID.
// It implements the api2go MarshalIdentifier and UnmarshalIdentitier interface.
type JAID struct {
ID string `json:"-"`
}
func NewJAID(id string) JAID {
return JAID{id}
}
// NewPrefixedJAID prefixes JAID with chain id in %s/%s format.
func NewPrefixedJAID(id string, chainID string) JAID {
return JAID{ID: fmt.Sprintf("%s/%s", chainID, id)}
}
// NewJAIDInt32 converts an int32 into a JAID
func NewJAIDInt32(id int32) JAID {
return JAID{strconv.Itoa(int(id))}
}
// NewJAIDInt64 converts an int64 into a JAID
func NewJAIDInt64(id int64) JAID {
return JAID{strconv.Itoa(int(id))}
}
// GetID implements the api2go MarshalIdentifier interface.
func (jaid JAID) GetID() string {
return jaid.ID
}
// SetID implements the api2go UnmarshalIdentitier interface.
func (jaid *JAID) SetID(value string) error {
jaid.ID = value
return nil
}