mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-04-19 19:59:13 +03:00
Show app version on the UI
This commit is contained in:
parent
8aa84b2be6
commit
9169e75e88
3 changed files with 19 additions and 3 deletions
6
main.go
6
main.go
|
@ -25,6 +25,10 @@ func main() {
|
||||||
fmt.Println("Build Time\t:", buildTime)
|
fmt.Println("Build Time\t:", buildTime)
|
||||||
fmt.Println("Git Repo\t:", "https://github.com/ngoduykhanh/wireguard-ui")
|
fmt.Println("Git Repo\t:", "https://github.com/ngoduykhanh/wireguard-ui")
|
||||||
|
|
||||||
|
// set app extra data
|
||||||
|
extraData := make(map[string]string)
|
||||||
|
extraData["appVersion"] = appVersion
|
||||||
|
|
||||||
// initialize DB
|
// initialize DB
|
||||||
err := util.InitDB()
|
err := util.InitDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -38,7 +42,7 @@ func main() {
|
||||||
assetHandler := http.FileServer(rice.MustFindBox("assets").HTTPBox())
|
assetHandler := http.FileServer(rice.MustFindBox("assets").HTTPBox())
|
||||||
|
|
||||||
// register routes
|
// register routes
|
||||||
app := router.New(tmplBox)
|
app := router.New(tmplBox, extraData)
|
||||||
|
|
||||||
app.GET("/", handler.WireGuardClients())
|
app.GET("/", handler.WireGuardClients())
|
||||||
app.GET("/login", handler.LoginPage())
|
app.GET("/login", handler.LoginPage())
|
||||||
|
|
|
@ -3,6 +3,7 @@ package router
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"reflect"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/GeertJohan/go.rice"
|
"github.com/GeertJohan/go.rice"
|
||||||
|
@ -16,6 +17,7 @@ import (
|
||||||
// TemplateRegistry is a custom html/template renderer for Echo framework
|
// TemplateRegistry is a custom html/template renderer for Echo framework
|
||||||
type TemplateRegistry struct {
|
type TemplateRegistry struct {
|
||||||
templates map[string]*template.Template
|
templates map[string]*template.Template
|
||||||
|
extraData map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render e.Renderer interface
|
// Render e.Renderer interface
|
||||||
|
@ -25,15 +27,24 @@ func (t *TemplateRegistry) Render(w io.Writer, name string, data interface{}, c
|
||||||
err := errors.New("Template not found -> " + name)
|
err := errors.New("Template not found -> " + name)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// inject more app data information. E.g. appVersion
|
||||||
|
if reflect.TypeOf(data).Kind() == reflect.Map {
|
||||||
|
for k, v := range t.extraData {
|
||||||
|
data.(map[string]interface{})[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// login page does not need the base layout
|
// login page does not need the base layout
|
||||||
if name == "login.html" {
|
if name == "login.html" {
|
||||||
return tmpl.Execute(w, data)
|
return tmpl.Execute(w, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
return tmpl.ExecuteTemplate(w, "base.html", data)
|
return tmpl.ExecuteTemplate(w, "base.html", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New function
|
// New function
|
||||||
func New(tmplBox *rice.Box) *echo.Echo {
|
func New(tmplBox *rice.Box, extraData map[string]string) *echo.Echo {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
e.Use(session.Middleware(sessions.NewCookieStore([]byte("secret"))))
|
e.Use(session.Middleware(sessions.NewCookieStore([]byte("secret"))))
|
||||||
|
|
||||||
|
@ -82,6 +93,7 @@ func New(tmplBox *rice.Box) *echo.Echo {
|
||||||
e.Validator = NewValidator()
|
e.Validator = NewValidator()
|
||||||
e.Renderer = &TemplateRegistry{
|
e.Renderer = &TemplateRegistry{
|
||||||
templates: templates,
|
templates: templates,
|
||||||
|
extraData: extraData,
|
||||||
}
|
}
|
||||||
|
|
||||||
return e
|
return e
|
||||||
|
|
|
@ -217,7 +217,7 @@
|
||||||
|
|
||||||
<footer class="main-footer">
|
<footer class="main-footer">
|
||||||
<div class="float-right d-none d-sm-block">
|
<div class="float-right d-none d-sm-block">
|
||||||
<b>Version</b> 0.1
|
<b>Version</b> {{ .appVersion }}
|
||||||
</div>
|
</div>
|
||||||
<strong>Copyright © 2020 <a href="https://github.com/ngoduykhanh/wireguard-ui">Wireguard UI</a>.</strong> All rights
|
<strong>Copyright © 2020 <a href="https://github.com/ngoduykhanh/wireguard-ui">Wireguard UI</a>.</strong> All rights
|
||||||
reserved.
|
reserved.
|
||||||
|
|
Loading…
Add table
Reference in a new issue