refactor: enhance code clarity and maintainability across multiple files

- Updated comments to improve clarity and adhere to best practices in ascii.go, main.go, and diagnostics.
- Removed unnecessary linter directives for improved readability in imaging.go and ptz.go.
- Reformatted function signatures and added helper calls in tests for consistency and clarity.
- Enhanced error handling and logging consistency in various server files, ensuring better maintainability.
This commit is contained in:
0x524a
2025-12-02 22:21:20 -05:00
parent c1daba5be6
commit 02f79ea7a7
12 changed files with 70 additions and 56 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ func ImageToASCII(imageData []byte, config ASCIIConfig) (string, error) {
// imageToASCIIFromImage is the core conversion function.
//
//nolint:gocyclo // Image to ASCII conversion has high complexity due to multiple pixel processing paths
//nolint:gocyclo,lll // Image to ASCII conversion has high complexity due to multiple pixel processing paths
func imageToASCIIFromImage(img image.Image, config ASCIIConfig, format string) (string, error) { //nolint:unparam // format reserved for future use
// Validate configuration
if config.Width <= 0 {
+7 -4
View File
@@ -280,6 +280,7 @@ func (c *CLI) performDiscoveryOnInterface(interfaceName string) ([]*discovery.De
if err != nil {
return nil, fmt.Errorf("discovery failed: %w", err)
}
return devices, nil
}
@@ -614,11 +615,13 @@ func (c *CLI) inspectRTSPStream(streamURI string) map[string]interface{} {
// Use rtspeek library for detailed stream inspection
ctx, cancel := context.WithTimeout(
context.Background(),
defaultRetryDelay*time.Second, //nolint:mnd // Stream inspection timeout
defaultRetryDelay*time.Second,
)
defer cancel()
streamInfo, err := sd.DescribeStream(ctx, streamURI, defaultRetryDelay*time.Second) //nolint:mnd // Stream description timeout
streamInfo, err := sd.DescribeStream(
ctx, streamURI, defaultRetryDelay*time.Second,
)
if err == nil && streamInfo != nil {
details["reachable"] = streamInfo.IsReachable()
@@ -685,7 +688,7 @@ func (c *CLI) tryRTSPConnection(streamURI string) map[string]interface{} {
}
// Try to connect
conn, err := net.DialTimeout("tcp", hostPort, maxRetries*time.Second) //nolint:mnd // Connection timeout
conn, err := net.DialTimeout("tcp", hostPort, maxRetries*time.Second)
if err == nil {
//nolint:errcheck // Close error is not critical for connectivity check
_ = conn.Close()
@@ -1615,7 +1618,7 @@ func (c *CLI) captureAndDisplaySnapshot(ctx context.Context) { //nolint:funlen /
filename = "snapshot.jpg"
}
if err := os.WriteFile(
filename, snapshotData, 0600, //nolint:gosec,mnd // 0600 appropriate for CLI output files
filename, snapshotData, 0600, //nolint:mnd // 0600 appropriate for CLI output files
); err != nil {
fmt.Printf("❌ Failed to save file: %v\n", err)
} else {