This makes the data easier to handle down the pipeline. Signed-off-by: Yonah <contrib@gensokyo.uk>
24 lines
458 B
Go
24 lines
458 B
Go
package monstersirenfetch
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strconv"
|
|
)
|
|
|
|
// StringInt is a JSON string representing an integer.
|
|
type StringInt int
|
|
|
|
func (i *StringInt) MarshalJSON() ([]byte, error) { return json.Marshal(strconv.Itoa(int(*i))) }
|
|
func (i *StringInt) UnmarshalJSON(data []byte) (err error) {
|
|
var v string
|
|
err = json.Unmarshal(data, &v)
|
|
if err == nil {
|
|
var n int
|
|
n, err = strconv.Atoi(v)
|
|
if err == nil {
|
|
*i = StringInt(n)
|
|
}
|
|
}
|
|
return
|
|
}
|