Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix-10519 #75

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ cd diagnostics
make build
```

Run the application. This may take a while. Expect to see a TLS Handshake error in the terminal
Run the application.
```
make run-self-signed
```
Expand All @@ -131,6 +131,8 @@ make run-self-signed
[Diagnostics setup](#diagnostics-set-up)

#### Step 2:
Open UI application in browser, you will find the link to it in console.

Follow these steps to create a session:

![create new operation session 1](/_images/create_session_1.png)
Expand Down
37 changes: 33 additions & 4 deletions cmd/diagnostics/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package main

import (
"bufio"
"context"
"fmt"
"log"
"net/http"
"os"
"os/exec"
"os/signal"
"runtime"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -59,7 +59,14 @@ func main() {
}
}()

open(fmt.Sprintf("http://%s:%d", listenAddr, listenPort))
packagePath := "github.com/ledgerwatch/erigonwatch"
version, err := GetPackageVersion(packagePath)
if err == nil {
fmt.Printf("Diagnostics version: %s\n", version)
}

fmt.Printf("Diagnostics UI is running on http://%s:%d\n", listenAddr, listenPort)
//open(fmt.Sprintf("http://%s:%d", listenAddr, listenPort))

// Graceful and eager terminations
switch s := <-signalCh; s {
Expand All @@ -75,7 +82,7 @@ func main() {
}

// open opens the specified URL in the default browser of the user.
func open(url string) error {
/*func open(url string) error {
var cmd string
var args []string

Expand All @@ -90,4 +97,26 @@ func open(url string) error {
}
args = append(args, url)
return exec.Command(cmd, args...).Start()
}*/

// GetPackageVersion returns the version of a package from the go.mod file.
func GetPackageVersion(packagePath string) (string, error) {
file, err := os.Open("./../../go.mod")
if err != nil {
return "", fmt.Errorf("failed to open go.mod file: %w", err)
}
defer file.Close()

scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "\t"+packagePath+" ") {
// Extract the version from the line
split := strings.Split(line, " ")
version := strings.TrimSpace(split[1])
return version, nil
}
}

return "", fmt.Errorf("package not found in go.mod file: %s", packagePath)
}
Loading