detached 0e99910

feat: improve version checking and logging

commit
0e99910835be300d4ee64fa07d3ac384c3ca7aac
author
bnema · · 2024-04-20 15:26 UTC
parent
1b3685a
signature
unsigned
4 files · +32 -17
A Makefile +19 -0
@@ -0,0 +1,19 @@
1+# Variables
2+INSTALL_DIR = /usr/bin
3+BINARY_NAME = gordon
4+# Default target
5+all: build
6+
7+# Build the Go binary
8+build:
9+ go build -o $(BINARY_NAME) cmd/cli/main.go
10+
11+# Install the binary to /usr/local/bin
12+install:
13+ mv $(BINARY_NAME) $(INSTALL_DIR)
14+
15+# Clean up the built binary
16+clean:
17+ rm -f $(BINARY_NAME)
18+
19+.PHONY: all build install clean⏎̸
@@ -0,0 +1,19 @@
1+# Variables
2+INSTALL_DIR = /usr/bin
3+BINARY_NAME = gordon
4+# Default target
5+all: build
6+
7+# Build the Go binary
8+build:
9+ go build -o $(BINARY_NAME) cmd/cli/main.go
10+
11+# Install the binary to /usr/local/bin
12+install:
13+ mv $(BINARY_NAME) $(INSTALL_DIR)
14+
15+# Clean up the built binary
16+clean:
17+ rm -f $(BINARY_NAME)
18+
19+.PHONY: all build install clean⏎̸
M cmd/cli/main.go +6 -9
@@ -46,9 +46,6 @@ func main() {
4646 ProxyURL: os.Getenv("PROXY_URL"),
4747 }
4848
49- // console log proxy url
50- log.Printf("Proxy URL: %s", buildInfo.ProxyURL)
51-
5249 a, err := cli.NewClientApp(buildInfo)
5350 if err != nil {
5451 fmt.Println("Error initializing app:", err)
@@ -61,12 +58,12 @@ func main() {
6158 common.DockerInit(&s.Config.ContainerEngine)
6259
6360 // Check for new version
64- //go func() {
65- //msg, err := common.CheckVersionPeriodically(&s.Config)
66- //if err != nil || msg != "" {
67- //log.Printf("CheckVersionPeriodically: %v %s", err, msg)
68- //}
69- //}()
61+ go func() {
62+ msg, err := common.CheckVersionPeriodically(&s.Config)
63+ if err != nil || msg != "" {
64+ log.Println(msg)
65+ }
66+ }()
7067
7168 Execute(a, s)
7269 }
@@ -46,9 +46,6 @@ func main() {
46 ProxyURL: os.Getenv("PROXY_URL"),46 ProxyURL: os.Getenv("PROXY_URL"),
47 }47 }
48 48
49- // console log proxy url
50- log.Printf("Proxy URL: %s", buildInfo.ProxyURL)
51-
52 a, err := cli.NewClientApp(buildInfo)49 a, err := cli.NewClientApp(buildInfo)
53 if err != nil {50 if err != nil {
54 fmt.Println("Error initializing app:", err)51 fmt.Println("Error initializing app:", err)
@@ -61,12 +58,12 @@ func main() {
61 common.DockerInit(&s.Config.ContainerEngine)58 common.DockerInit(&s.Config.ContainerEngine)
62 59
63 // Check for new version60 // Check for new version
64- //go func() {61+ go func() {
65- //msg, err := common.CheckVersionPeriodically(&s.Config)62+ msg, err := common.CheckVersionPeriodically(&s.Config)
66- //if err != nil || msg != "" {63+ if err != nil || msg != "" {
67- //log.Printf("CheckVersionPeriodically: %v %s", err, msg)64+ log.Println(msg)
68- //}65+ }
69- //}()66+ }()
70 67
71 Execute(a, s)68 Execute(a, s)
72 }69 }
M internal/common/version.go +6 -6
@@ -7,6 +7,7 @@ import (
77 "log"
88 "net/http"
99 "runtime"
10+ "strings"
1011 "time"
1112
1213 "github.com/bnema/gordon/pkg/docker"
@@ -67,6 +68,11 @@ func checkAndUpdateVersion(c *Config) (string, error) {
6768 remoteVersion = remoteVersions.Name
6869 }
6970
71+ // Check if remoteVersion is empty or doesn't contain the architecture suffix
72+ if remoteVersion == "" || !strings.Contains(remoteVersion, getArch()) {
73+ return "", fmt.Errorf("remote version not available for architecture %s", getArch())
74+ }
75+
7076 remoteVersion = remoteVersion[:len(remoteVersion)-len(getArch())-1]
7177 message := CheckForNewVersion(localVersion.Version, remoteVersion)
7278
@@ -84,7 +90,6 @@ func checkAndUpdateVersion(c *Config) (string, error) {
8490 }
8591
8692 return "", nil
87-
8893 }
8994
9095 func CheckVersionPeriodically(c *Config) (string, error) {
@@ -120,11 +125,6 @@ func CheckVersionPeriodically(c *Config) (string, error) {
120125 return "", nil
121126 }
122127
123-// func getLocalVersion(c *Config) CurrentVersion {
124-// // Dummy implementation, replace with your actual logic
125-// return CurrentVersion{Version: "0.0.970"} // Example version
126-// }
127-
128128 func getRemoteVersion(c *Config) (VersionsResponse, error) {
129129 proxyURL := c.Build.ProxyURL
130130 if proxyURL == "" {
@@ -7,6 +7,7 @@ import (
7 "log"7 "log"
8 "net/http"8 "net/http"
9 "runtime"9 "runtime"
10+ "strings"
10 "time"11 "time"
11 12
12 "github.com/bnema/gordon/pkg/docker"13 "github.com/bnema/gordon/pkg/docker"
@@ -67,6 +68,11 @@ func checkAndUpdateVersion(c *Config) (string, error) {
67 remoteVersion = remoteVersions.Name68 remoteVersion = remoteVersions.Name
68 }69 }
69 70
71+ // Check if remoteVersion is empty or doesn't contain the architecture suffix
72+ if remoteVersion == "" || !strings.Contains(remoteVersion, getArch()) {
73+ return "", fmt.Errorf("remote version not available for architecture %s", getArch())
74+ }
75+
70 remoteVersion = remoteVersion[:len(remoteVersion)-len(getArch())-1]76 remoteVersion = remoteVersion[:len(remoteVersion)-len(getArch())-1]
71 message := CheckForNewVersion(localVersion.Version, remoteVersion)77 message := CheckForNewVersion(localVersion.Version, remoteVersion)
72 78
@@ -84,7 +90,6 @@ func checkAndUpdateVersion(c *Config) (string, error) {
84 }90 }
85 91
86 return "", nil92 return "", nil
87-
88 }93 }
89 94
90 func CheckVersionPeriodically(c *Config) (string, error) {95 func CheckVersionPeriodically(c *Config) (string, error) {
@@ -120,11 +125,6 @@ func CheckVersionPeriodically(c *Config) (string, error) {
120 return "", nil125 return "", nil
121 }126 }
122 127
123-// func getLocalVersion(c *Config) CurrentVersion {
124-// // Dummy implementation, replace with your actual logic
125-// return CurrentVersion{Version: "0.0.970"} // Example version
126-// }
127-
128 func getRemoteVersion(c *Config) (VersionsResponse, error) {128 func getRemoteVersion(c *Config) (VersionsResponse, error) {
129 proxyURL := c.Build.ProxyURL129 proxyURL := c.Build.ProxyURL
130 if proxyURL == "" {130 if proxyURL == "" {
M internal/server/sqliteinit.go +1 -2
@@ -17,6 +17,7 @@ const (
1717
1818 func (a *App) getDiskDBFilePath() string {
1919 DiskDBfilepath := filepath.Join(a.DBDir, a.DBFilename)
20+ // if a.DBDir is empty return log "Set a path using storageDir in the config file"
2021 return DiskDBfilepath
2122 }
2223
@@ -59,7 +60,6 @@ func InitializeDB(a *App) (*sql.DB, error) {
5960 }
6061 }
6162
62- // Change here from "sqlite3" to "sqlite"
6363 db, err := sql.Open("sqlite", dbPath)
6464 if err != nil {
6565 return nil, fmt.Errorf("failed to open disk DB: %w", err)
@@ -78,7 +78,6 @@ func InitializeDB(a *App) (*sql.DB, error) {
7878 }
7979
8080 func bootstrapDB(dbPath string, app *App) error {
81- // Change here from "sqlite3" to "sqlite"
8281 db, err := sql.Open("sqlite", dbPath)
8382 if err != nil {
8483 return err
@@ -17,6 +17,7 @@ const (
17 17
18 func (a *App) getDiskDBFilePath() string {18 func (a *App) getDiskDBFilePath() string {
19 DiskDBfilepath := filepath.Join(a.DBDir, a.DBFilename)19 DiskDBfilepath := filepath.Join(a.DBDir, a.DBFilename)
20+ // if a.DBDir is empty return log "Set a path using storageDir in the config file"
20 return DiskDBfilepath21 return DiskDBfilepath
21 }22 }
22 23
@@ -59,7 +60,6 @@ func InitializeDB(a *App) (*sql.DB, error) {
59 }60 }
60 }61 }
61 62
62- // Change here from "sqlite3" to "sqlite"
63 db, err := sql.Open("sqlite", dbPath)63 db, err := sql.Open("sqlite", dbPath)
64 if err != nil {64 if err != nil {
65 return nil, fmt.Errorf("failed to open disk DB: %w", err)65 return nil, fmt.Errorf("failed to open disk DB: %w", err)
@@ -78,7 +78,6 @@ func InitializeDB(a *App) (*sql.DB, error) {
78 }78 }
79 79
80 func bootstrapDB(dbPath string, app *App) error {80 func bootstrapDB(dbPath string, app *App) error {
81- // Change here from "sqlite3" to "sqlite"
82 db, err := sql.Open("sqlite", dbPath)81 db, err := sql.Open("sqlite", dbPath)
83 if err != nil {82 if err != nil {
84 return err83 return err

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close