mirror of
https://github.com/henrygd/beszel.git
synced 2026-04-10 23:11:50 +02:00
refactor: small go 1.26 updates and go fix changes
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package agent
|
package agent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@@ -91,8 +91,8 @@ func (c *ConnectionManager) Start(serverOptions ServerOptions) error {
|
|||||||
c.eventChan = make(chan ConnectionEvent, 1)
|
c.eventChan = make(chan ConnectionEvent, 1)
|
||||||
|
|
||||||
// signal handling for shutdown
|
// signal handling for shutdown
|
||||||
sigChan := make(chan os.Signal, 1)
|
sigCtx, stopSignals := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||||
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
|
defer stopSignals()
|
||||||
|
|
||||||
c.startWsTicker()
|
c.startWsTicker()
|
||||||
c.connect()
|
c.connect()
|
||||||
@@ -109,8 +109,8 @@ func (c *ConnectionManager) Start(serverOptions ServerOptions) error {
|
|||||||
_ = c.startWebSocketConnection()
|
_ = c.startWebSocketConnection()
|
||||||
case <-healthTicker:
|
case <-healthTicker:
|
||||||
_ = health.Update()
|
_ = health.Update()
|
||||||
case <-sigChan:
|
case <-sigCtx.Done():
|
||||||
slog.Info("Shutting down")
|
slog.Info("Shutting down", "cause", context.Cause(sigCtx))
|
||||||
_ = c.agent.StopServer()
|
_ = c.agent.StopServer()
|
||||||
c.closeWebSocket()
|
c.closeWebSocket()
|
||||||
return health.CleanUp()
|
return health.CleanUp()
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
|
|||||||
@@ -89,10 +89,7 @@ func getPerCoreCpuUsage(cacheTimeMs uint16) (system.Uint8Slice, error) {
|
|||||||
lastTimes := lastPerCoreCpuTimes[cacheTimeMs]
|
lastTimes := lastPerCoreCpuTimes[cacheTimeMs]
|
||||||
|
|
||||||
// Limit to the number of cores available in both samples
|
// Limit to the number of cores available in both samples
|
||||||
length := len(perCoreTimes)
|
length := min(len(lastTimes), len(perCoreTimes))
|
||||||
if len(lastTimes) < length {
|
|
||||||
length = len(lastTimes)
|
|
||||||
}
|
|
||||||
|
|
||||||
usage := make([]uint8, length)
|
usage := make([]uint8, length)
|
||||||
for i := 0; i < length; i++ {
|
for i := 0; i < length; i++ {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ func (a *Agent) initializeDiskInfo() {
|
|||||||
|
|
||||||
// Add EXTRA_FILESYSTEMS env var values to fsStats
|
// Add EXTRA_FILESYSTEMS env var values to fsStats
|
||||||
if extraFilesystems, exists := GetEnv("EXTRA_FILESYSTEMS"); exists {
|
if extraFilesystems, exists := GetEnv("EXTRA_FILESYSTEMS"); exists {
|
||||||
for _, fsEntry := range strings.Split(extraFilesystems, ",") {
|
for fsEntry := range strings.SplitSeq(extraFilesystems, ",") {
|
||||||
// Parse custom name from format: device__customname
|
// Parse custom name from format: device__customname
|
||||||
fs, customName := parseFilesystemEntry(fsEntry)
|
fs, customName := parseFilesystemEntry(fsEntry)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package health
|
package health
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
|
|||||||
@@ -476,7 +476,7 @@ func (sm *SmartManager) CollectSmart(deviceInfo *DeviceInfo) error {
|
|||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
|
|
||||||
// Check if device is in standby (exit status 2)
|
// Check if device is in standby (exit status 2)
|
||||||
if exitErr, ok := err.(*exec.ExitError); ok && exitErr.ExitCode() == 2 {
|
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok && exitErr.ExitCode() == 2 {
|
||||||
if hasExistingData {
|
if hasExistingData {
|
||||||
// Device is in standby and we have cached data, keep using cache
|
// Device is in standby and we have cached data, keep using cache
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package alerts_test
|
package alerts_test
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package alerts_test
|
package alerts_test
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package alerts_test
|
package alerts_test
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package alerts_test
|
package alerts_test
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package alerts
|
package alerts
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func ColorPrint(color, text string) {
|
|||||||
fmt.Println(color + text + colorReset)
|
fmt.Println(color + text + colorReset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ColorPrintf(color, format string, args ...interface{}) {
|
func ColorPrintf(color, format string, args ...any) {
|
||||||
fmt.Printf(color+format+colorReset+"\n", args...)
|
fmt.Printf(color+format+colorReset+"\n", args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package hub
|
package hub
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package config_test
|
package config_test
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package expirymap
|
package expirymap
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package heartbeat_test
|
package heartbeat_test
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package hub_test
|
package hub_test
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package hub
|
package hub
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build !testing
|
//go:build !testing
|
||||||
// +build !testing
|
|
||||||
|
|
||||||
package systems
|
package systems
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package systems_test
|
package systems_test
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package systems
|
package systems
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package ws
|
package ws
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package ws
|
package ws
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package ws
|
package ws
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package records_test
|
package records_test
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
package records
|
package records
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build testing
|
//go:build testing
|
||||||
// +build testing
|
|
||||||
|
|
||||||
// Package tests provides helpers for testing the application.
|
// Package tests provides helpers for testing the application.
|
||||||
package tests
|
package tests
|
||||||
|
|||||||
Reference in New Issue
Block a user