datasize icon indicating copy to clipboard operation
datasize copied to clipboard

Add ParseAs and ParseStringAs functions

Open SVilgelm opened this issue 1 year ago • 2 comments

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.

SVilgelm avatar Oct 10 '22 00:10 SVilgelm

@c2h5oh Hi, could you please review this PR?

SVilgelm avatar Oct 14 '22 04:10 SVilgelm

@c2h5oh Hi, could you please review this PR?

SVilgelm avatar Oct 20 '22 20:10 SVilgelm