generic: move StringInt padding to string method
This allows the implementation to be reused for url and filename formatting in the downloader. Signed-off-by: Yonah <contrib@gensokyo.uk>
This commit is contained in:
parent
ea54772c03
commit
2d6b87702d
@ -39,16 +39,17 @@ func (s *NullableString) UnmarshalJSON(data []byte) (err error) {
|
|||||||
// StringInt is a JSON string representing an integer.
|
// StringInt is a JSON string representing an integer.
|
||||||
type StringInt int
|
type StringInt int
|
||||||
|
|
||||||
func (i *StringInt) MarshalJSON() ([]byte, error) {
|
func (i *StringInt) String() (s string) {
|
||||||
s := strconv.Itoa(int(*i))
|
s = strconv.Itoa(int(*i))
|
||||||
if len(s) <= 4 {
|
if len(s) <= 4 {
|
||||||
s = strings.Repeat("0", 4-len(s)) + s
|
s = strings.Repeat("0", 4-len(s)) + s
|
||||||
} else if len(s) < 6 {
|
} else if len(s) < 6 {
|
||||||
s = strings.Repeat("0", 6-len(s)) + s
|
s = strings.Repeat("0", 6-len(s)) + s
|
||||||
}
|
}
|
||||||
return json.Marshal(s)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *StringInt) MarshalJSON() ([]byte, error) { return json.Marshal(i.String()) }
|
||||||
func (i *StringInt) UnmarshalJSON(data []byte) (err error) {
|
func (i *StringInt) UnmarshalJSON(data []byte) (err error) {
|
||||||
var v string
|
var v string
|
||||||
err = json.Unmarshal(data, &v)
|
err = json.Unmarshal(data, &v)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user