feat: refactor configuration + html page template data

This commit is contained in:
2023-09-24 09:33:20 -06:00
parent c2f8be504e
commit bf14a70efe
10 changed files with 59 additions and 43 deletions

View File

@ -1,10 +1,19 @@
package http
import "log"
import (
"log"
)
type Options struct {
Logger func(message string, args ...any)
CustomDir string `env:"CUSTOM_DIR"`
Logger func(message string, args ...any)
CustomDir string `env:"CUSTOM_DIR"`
TemplateData *TemplateData `envPrefix:"TEMPLATE_DATA_"`
}
type TemplateData struct {
Title string `env:"TITLE"`
SSHPublicHost string `env:"SSH_PUBLIC_HOST"`
SSHPublicPort int `env:"SSH_PUBLIC_PORT"`
}
type OptionFunc func(*Options)
@ -13,6 +22,11 @@ func DefaultOptions() *Options {
return &Options{
Logger: log.Printf,
CustomDir: "",
TemplateData: &TemplateData{
Title: "Rebound",
SSHPublicHost: "127.0.0.1",
SSHPublicPort: 2222,
},
}
}
@ -27,3 +41,9 @@ func WithCustomDir(customDir string) func(*Options) {
opts.CustomDir = customDir
}
}
func WithTemplateData(templateData *TemplateData) func(*Options) {
return func(opts *Options) {
opts.TemplateData = templateData
}
}

View File

@ -30,13 +30,7 @@ type Server struct {
}
func (s *Server) serveHomepage(w http.ResponseWriter, r *http.Request) {
data := struct {
Title string
}{
Title: "Rebound",
}
s.renderTemplate(w, "index", data)
s.renderTemplate(w, "index", s.opts.TemplateData)
}
func (s *Server) Serve(l net.Listener) error {

View File

@ -2,7 +2,7 @@
<footer class="footer">
<div class="container">
<div class="content has-text-centered">
Ce service est propulsé par Rebound, un logiciel libre diffusé sous licence <a href="#">AGPL-3.0</a>.
Ce service est propulsé par <a href="https://forge.cadoles.com/wpetit/rebound" title="Rebound repository">Rebound</a>, un logiciel libre diffusé sous licence <a href="https://www.gnu.org/licenses/agpl-3.0.en.html#license-text">AGPL-3.0</a>.
</div>
</div>
</footer>

View File

@ -17,7 +17,7 @@
<p>Rebound est un serveur SSH permettant de créer des tunnels TCP/IP éphémères et privés entre 2 machines positionnées
derrière un <abbr title="Network Address Traversal">NAT</abbr>.</p>
<p>Pour l'utiliser <strong>un simple client SSH suffit !</strong></p>
<pre class="has-background-dark has-text-white-ter is-family-monospace">ssh -R 0:127.0.0.1:<span class="has-text-info">&lt;port&gt;</span> rebound@rebound.cadol.es</pre>
<pre class="has-background-dark has-text-white-ter is-family-monospace">ssh -R 0:127.0.0.1:<span class="has-text-info">&lt;port&gt;</span> rebound@{{ .SSHPublicHost }} -p {{ .SSHPublicPort }}</pre>
<p class="is-italic"><span class="has-text-info">&lt;port&gt;</span> est à remplacer par le port du service
s'exécutant sur votre machine en local.</span>
<p>Une fois connecté, suivez les instructions. 😉</p>