feat: show version in admin page
This commit is contained in:
parent
c920eb94a0
commit
a0f12efd65
3 changed files with 41 additions and 14 deletions
|
@ -46,6 +46,7 @@ type TemplateData struct {
|
||||||
Channels []*model.Channel
|
Channels []*model.Channel
|
||||||
Channel *model.Channel
|
Channel *model.Channel
|
||||||
ChannelPlugin *model.ChannelPlugin
|
ChannelPlugin *model.ChannelPlugin
|
||||||
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Admin represents the admin interface
|
// Admin represents the admin interface
|
||||||
|
@ -55,10 +56,11 @@ type Admin struct {
|
||||||
store *sessions.CookieStore
|
store *sessions.CookieStore
|
||||||
templates map[string]*template.Template
|
templates map[string]*template.Template
|
||||||
baseTemplate *template.Template
|
baseTemplate *template.Template
|
||||||
|
version string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new Admin instance
|
// New creates a new Admin instance
|
||||||
func New(cfg *config.Config, database *db.Database) *Admin {
|
func New(cfg *config.Config, database *db.Database, version string) *Admin {
|
||||||
// Create session store with appropriate options
|
// Create session store with appropriate options
|
||||||
store := sessions.NewCookieStore([]byte(cfg.SecretKey))
|
store := sessions.NewCookieStore([]byte(cfg.SecretKey))
|
||||||
store.Options = &sessions.Options{
|
store.Options = &sessions.Options{
|
||||||
|
@ -126,6 +128,7 @@ func New(cfg *config.Config, database *db.Database) *Admin {
|
||||||
store: store,
|
store: store,
|
||||||
templates: templates,
|
templates: templates,
|
||||||
baseTemplate: baseTemplate,
|
baseTemplate: baseTemplate,
|
||||||
|
version: version,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,6 +267,7 @@ func (a *Admin) render(w http.ResponseWriter, r *http.Request, templateName stri
|
||||||
data.LoggedIn = a.isLoggedIn(r)
|
data.LoggedIn = a.isLoggedIn(r)
|
||||||
data.Path = r.URL.Path
|
data.Path = r.URL.Path
|
||||||
data.Flash = a.getFlashes(w, r)
|
data.Flash = a.getFlashes(w, r)
|
||||||
|
data.Version = a.version
|
||||||
|
|
||||||
// Get template
|
// Get template
|
||||||
tmpl, ok := a.templates[templateName]
|
tmpl, ok := a.templates[templateName]
|
||||||
|
|
|
@ -117,6 +117,19 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<footer class="footer footer-transparent d-print-none">
|
||||||
|
<div class="container-xl">
|
||||||
|
<div class="row text-center align-items-center flex-row-reverse">
|
||||||
|
<div class="col-12 col-lg-auto mt-3 mt-lg-0">
|
||||||
|
<ul class="list-inline list-inline-dots mb-0">
|
||||||
|
<li class="list-inline-item">
|
||||||
|
ButterRobot {{if .Version}}v{{.Version}}{{else}}(development){{end}}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://unpkg.com/@tabler/core@latest/dist/js/tabler.min.js"></script>
|
<script src="https://unpkg.com/@tabler/core@latest/dist/js/tabler.min.js"></script>
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
@ -26,12 +27,13 @@ import (
|
||||||
|
|
||||||
// App represents the application
|
// App represents the application
|
||||||
type App struct {
|
type App struct {
|
||||||
config *config.Config
|
config *config.Config
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
db *db.Database
|
db *db.Database
|
||||||
router *http.ServeMux
|
router *http.ServeMux
|
||||||
queue *queue.Queue
|
queue *queue.Queue
|
||||||
admin *admin.Admin
|
admin *admin.Admin
|
||||||
|
version string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new App instance
|
// New creates a new App instance
|
||||||
|
@ -48,16 +50,24 @@ func New(cfg *config.Config, logger *slog.Logger) (*App, error) {
|
||||||
// Initialize message queue
|
// Initialize message queue
|
||||||
messageQueue := queue.New(logger)
|
messageQueue := queue.New(logger)
|
||||||
|
|
||||||
|
// Get version information
|
||||||
|
version := ""
|
||||||
|
info, ok := debug.ReadBuildInfo()
|
||||||
|
if ok {
|
||||||
|
version = info.Main.Version
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize admin interface
|
// Initialize admin interface
|
||||||
adminInterface := admin.New(cfg, database)
|
adminInterface := admin.New(cfg, database, version)
|
||||||
|
|
||||||
return &App{
|
return &App{
|
||||||
config: cfg,
|
config: cfg,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
db: database,
|
db: database,
|
||||||
router: router,
|
router: router,
|
||||||
queue: messageQueue,
|
queue: messageQueue,
|
||||||
admin: adminInterface,
|
admin: adminInterface,
|
||||||
|
version: version,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue