oxzi / gosh

Authenticationless HTTP file upload server
GNU General Public License v3.0
16 stars 2 forks source link

Allow templating of the web frontend #31

Closed riotbib closed 11 months ago

riotbib commented 1 year ago

Dear @oxzi, for me it would be helpful, if gosh would allow the templating of the web fronted.

Thus I could change the design of the HTML and CSS to adapt to the use case of gosh.

My skills in Golang are limited. Would you assist me learning how to implement this?

Or could you add this feature if you deem it necessary aswell?

Thanks.

oxzi commented 1 year ago

On 2023-05-28 08:56, Lennart Mühlenmeier @.***> wrote:

Dear @oxzi, for me it would be helpful, if gosh would allow the templating of the web fronted.

This feature would be great. A possible implementation could default to the current template, which can be overwritten through a template file passed as a command line argument.

My skills in Golang are limited. Would you assist me learning how to implement this?

Currently, the template resides within a constant string variable [0]. The HTTP handler for GET request against "/", handleIndex, then creates a new Golang text/template [1] for this variable[2] and populates it with an ad hoc generated struct of the necessary values.

The struct field names are also present within the template, e.g., the Expires field fills {{.Expires}}.

A possible solution would be to introduce a new field for a template to the Server struct, which can be set during the NewServer call. When this field is nil, the current const indexTpl will be used. Within goshd, a command line argument can be introduced for a template file, which, when set, will be read and passed as a string (?) to NewServer.

This would only one way to implement this and there might be better ones.

Btw, using text/template to generate HTML is kind of hackish and a dirty solution. Thus, this should at least be changed to html/template one day.

Cheers!

[0] https://github.com/oxzi/gosh/blob/76c526876303c4470dd29c190de0057e5000d3de/internal/server.go#L15-L159 [1] https://pkg.go.dev/text/template [2] https://github.com/oxzi/gosh/blob/76c526876303c4470dd29c190de0057e5000d3de/internal/server.go#L236 [3] https://github.com/oxzi/gosh/blob/76c526876303c4470dd29c190de0057e5000d3de/internal/server.go#L245-L261

riotbib commented 1 year ago

Thanks, @oxzi. I know some of these words. I'll get back to you, once I learned how to do, what you described.

Until then, feel free to start hacking on this feature!

Cheers!

Prost!