From b09796bf7e7520a5a89936487b2573307936fd8a Mon Sep 17 00:00:00 2001 From: Ludvig Lundgren Date: Sun, 2 Jan 2022 15:18:28 +0100 Subject: [PATCH] Feature: Set and display version info (#63) * chore: update packages * feat: show version info * build: remove ldflags override --- .goreleaser.yml | 4 ---- cmd/autobrr/main.go | 11 +++++++++-- go.mod | 1 - go.sum | 1 - internal/http/config.go | 15 +++++++++++++-- internal/http/server.go | 11 +++++++++-- internal/logger/logger.go | 3 --- web/src/domain/interfaces.ts | 3 +++ web/src/screens/settings/Application.tsx | 16 ++++++++++++++++ 9 files changed, 50 insertions(+), 15 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index f9c9f80..3b13222 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -22,8 +22,6 @@ builds: goarch: arm64 main: ./cmd/autobrr/main.go binary: autobrr - ldflags: - - -s -w - id: autobrrctl env: - CGO_ENABLED=0 @@ -43,8 +41,6 @@ builds: goarch: arm64 main: ./cmd/autobrrctl/main.go binary: autobrrctl - ldflags: - - -s -w archives: - id: autobrr diff --git a/cmd/autobrr/main.go b/cmd/autobrr/main.go index 141fa77..ca73b01 100644 --- a/cmd/autobrr/main.go +++ b/cmd/autobrr/main.go @@ -31,7 +31,10 @@ import ( ) var ( - cfg domain.Config + cfg domain.Config + version = "dev" + commit = "" + date = "" ) func main() { @@ -54,6 +57,10 @@ func main() { // setup logger logger.Setup(cfg, serverEvents) + log.Info().Msg("Starting autobrr") + log.Info().Msgf("Version: %v", version) + log.Info().Msgf("Log-level: %v", cfg.LogLevel) + // if configPath is set then put database inside that path, otherwise create wherever it's run var dataSource = database.DataSourceName(configPath, "autobrr.db") @@ -100,7 +107,7 @@ func main() { errorChannel := make(chan error) go func() { - httpServer := http.NewServer(serverEvents, addr, cfg.BaseURL, actionService, authService, downloadClientService, filterService, indexerService, ircService, releaseService) + httpServer := http.NewServer(serverEvents, addr, cfg.BaseURL, version, commit, date, actionService, authService, downloadClientService, filterService, indexerService, ircService, releaseService) errorChannel <- httpServer.Open() }() diff --git a/go.mod b/go.mod index 7fcf0e4..ba25957 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/gdm85/go-libdeluge v0.5.5 github.com/go-chi/chi v1.5.4 github.com/gorilla/sessions v1.2.1 - github.com/gorilla/websocket v1.4.2 github.com/lib/pq v1.10.4 github.com/mattn/go-isatty v0.0.14 // indirect github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index e38710c..6780fce 100644 --- a/go.sum +++ b/go.sum @@ -446,7 +446,6 @@ github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+ github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gosuri/uilive v0.0.0-20170323041506-ac356e6e42cd/go.mod h1:qkLSc0A5EXSP6B04TrN4oQoxqFI7A8XvoXSlJi8cwk8= github.com/gosuri/uilive v0.0.3/go.mod h1:qkLSc0A5EXSP6B04TrN4oQoxqFI7A8XvoXSlJi8cwk8= diff --git a/internal/http/config.go b/internal/http/config.go index 8c2d553..2a2e38a 100644 --- a/internal/http/config.go +++ b/internal/http/config.go @@ -14,14 +14,22 @@ type configJson struct { LogLevel string `json:"log_level"` LogPath string `json:"log_path"` BaseURL string `json:"base_url"` + Version string `json:"version"` + Commit string `json:"commit"` + Date string `json:"date"` } type configHandler struct { encoder encoder + + server Server } -func newConfigHandler(encoder encoder) *configHandler { - return &configHandler{encoder: encoder} +func newConfigHandler(encoder encoder, server Server) *configHandler { + return &configHandler{ + encoder: encoder, + server: server, + } } func (h configHandler) Routes(r chi.Router) { @@ -39,6 +47,9 @@ func (h configHandler) getConfig(w http.ResponseWriter, r *http.Request) { LogLevel: c.LogLevel, LogPath: c.LogPath, BaseURL: c.BaseURL, + Version: h.server.version, + Commit: h.server.commit, + Date: h.server.date, } h.encoder.StatusResponse(ctx, w, conf, http.StatusOK) diff --git a/internal/http/server.go b/internal/http/server.go index 93acfe7..4126bcf 100644 --- a/internal/http/server.go +++ b/internal/http/server.go @@ -19,6 +19,10 @@ type Server struct { address string baseUrl string + version string + commit string + date string + actionService actionService authService authService downloadClientService downloadClientService @@ -28,11 +32,14 @@ type Server struct { releaseService releaseService } -func NewServer(sse *sse.Server, address string, baseUrl string, actionService actionService, authService authService, downloadClientSvc downloadClientService, filterSvc filterService, indexerSvc indexerService, ircSvc ircService, releaseSvc releaseService) Server { +func NewServer(sse *sse.Server, address string, baseUrl string, version string, commit string, date string, actionService actionService, authService authService, downloadClientSvc downloadClientService, filterSvc filterService, indexerSvc indexerService, ircSvc ircService, releaseSvc releaseService) Server { return Server{ sse: sse, address: address, baseUrl: baseUrl, + version: version, + commit: commit, + date: date, actionService: actionService, authService: authService, @@ -91,7 +98,7 @@ func (s Server) Handler() http.Handler { r.Route("/api", func(r chi.Router) { r.Route("/actions", newActionHandler(encoder, s.actionService).Routes) - r.Route("/config", newConfigHandler(encoder).Routes) + r.Route("/config", newConfigHandler(encoder, s).Routes) r.Route("/download_clients", newDownloadClientHandler(encoder, s.downloadClientService).Routes) r.Route("/filters", newFilterHandler(encoder, s.filterService).Routes) r.Route("/irc", newIrcHandler(encoder, s.ircService).Routes) diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 7281ef5..59df272 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -50,7 +50,4 @@ func Setup(cfg domain.Config, sse *sse.Server) { log.Logger = log.Hook(&ServerSentEventHook{sse: sse}) log.Logger = log.Output(writers) - - log.Print("Starting autobrr") - log.Printf("Log-level: %v", cfg.LogLevel) } diff --git a/web/src/domain/interfaces.ts b/web/src/domain/interfaces.ts index a4e6feb..2fc1461 100644 --- a/web/src/domain/interfaces.ts +++ b/web/src/domain/interfaces.ts @@ -169,6 +169,9 @@ export interface Config { log_level: string; log_path: string; base_url: string; + version: string; + commit: string; + date: string; } export interface Release { diff --git a/web/src/screens/settings/Application.tsx b/web/src/screens/settings/Application.tsx index a9527b8..417ae76 100644 --- a/web/src/screens/settings/Application.tsx +++ b/web/src/screens/settings/Application.tsx @@ -80,6 +80,22 @@ function ApplicationSettings() {
+
+
+
+
Version:
+
{data?.version}
+
+
+
Commit:
+
{data?.commit}
+
+
+
Date:
+
{data?.date}
+
+
+