Function for human readable bytes

I would like to display the max_filesize ( caddyv2-upload/upload.go at main · git001/caddyv2-upload · GitHub ) in the HTML form in human readable form caddyv2-upload/upload-template.html at main · git001/caddyv2-upload · GitHub is there already a function for this in caddy or should I use my own?

Something like pretty-go-bytes/index.go at master · jldeep/pretty-go-bytes · GitHub

Are you interested on a pull request for caddy/tplcontext.go at master · caddyserver/caddy · GitHub ?

Can a placeholder be chained like this example

{{ placeholder "http.upload.max_filesize" | pretty_print_bytes }}
1 Like

I could see a humanize function being a worthy addition to the templates func map. We already have a dependency on a humanization library which is pretty good, so I think it should be pretty straightforward.

(It’d probably be a more generic function where you specify the unit as an argument.)

2 Likes

FWIW it’s this one:

So if you want to write a PR to add a function to templates using that, sure :+1:

2 Likes

Added feature request to gh issues [Feature] Add template function for human readable · Issue #4766 · caddyserver/caddy · GitHub

Have now added the PR Add size and time formating for human readable. close #4766 by git001 · Pull Request #4767 · caddyserver/caddy · GitHub

Where and how can i add this to the documentation?

2 Likes

I gave it a review :slight_smile:

2 Likes

This topic was automatically closed after 60 days. New replies are no longer allowed.