datasize
datasize copied to clipboard
Add ParseAs and ParseStringAs functions
Sometimes we want to use a different unit as base. We have an API that returns a link to download a file instead of returnning it as the responses if the size of the file is greater than given limit: GET /v1/data/<id>?limit=20
and we want to let a user to use just a number without any units and parse it as megabytes, not as bytes.
To solve this I have created a simple helper and want to contribute it back to upstream, maybe it can be useful to anyone else. The helper just uses strconv.ParseUint to validate that the given size can be parsed as Uint64 and then multiplies it to given base, if no then just uses dafault Parser fucntion.
@c2h5oh Hi, could you please review this PR?
@c2h5oh Hi, could you please review this PR?