style: Extract UI constants and refactor main view rendering (#30)

- [x] Add golangci-lint configuration with gocritic ifElseChain disabled
- [x] Rename error variables to avoid shadowing (createErr, watcherErr, watchErr, etc.)
- [x] Replace `interface{}` with `any` type alias throughout codebase
- [x] Add package-level documentation comments to all internal packages
- [x] Reorder struct fields alphabetically for consistency
- [x] Extract UI constants (terminal dimensions, column widths, colors) to constants.go
- [x] Refactor BubbleTeaUI main view rendering into smaller helper functions
- [x] Simplify nested conditionals and improve code clarity
- [x] Add `isForwardDisabled()` helper method to BubbleTeaUI
- [x] Update file permissions from 0644 to 0600 in config tests
- [x] Add `#nosec` comments and error suppression where appropriate
- [x] Improve test table struct field ordering for readability
- [x] Fix resource parsing in AddForward using strings.SplitN
- [x] Add comprehensive tests for new UI helper functions and constants
This commit is contained in:
2026-01-13 09:37:45 +00:00
committed by GitHub
parent 3d71f64901
commit 96ae1d45e0
54 changed files with 1319 additions and 730 deletions
+14 -5
View File
@@ -1,3 +1,12 @@
// Package converter provides configuration migration from other port-forwarding
// tools to kportal's YAML format. Currently supports kftray JSON format.
//
// Basic usage:
//
// err := converter.ConvertKFTrayToKPortal("kftray.json", ".kportal.yaml")
// if err != nil {
// log.Fatal(err)
// }
package converter
import (
@@ -14,12 +23,12 @@ import (
type KFTrayConfig struct {
Service string `json:"service"`
Namespace string `json:"namespace"`
LocalPort int `json:"local_port"`
RemotePort int `json:"remote_port"`
Context string `json:"context"`
WorkloadType string `json:"workload_type"`
Protocol string `json:"protocol"`
Alias string `json:"alias"`
LocalPort int `json:"local_port"`
RemotePort int `json:"remote_port"`
}
// ConvertKFTrayToKPortal converts kftray JSON configuration to kportal YAML format
@@ -32,8 +41,8 @@ func ConvertKFTrayToKPortal(inputFile, outputFile string) error {
}
var kftrayConfigs []KFTrayConfig
if err := json.Unmarshal(data, &kftrayConfigs); err != nil {
return fmt.Errorf("failed to parse JSON: %w", err)
if unmarshalErr := json.Unmarshal(data, &kftrayConfigs); unmarshalErr != nil {
return fmt.Errorf("failed to parse JSON: %w", unmarshalErr)
}
// Convert to kportal format
@@ -169,9 +178,9 @@ type namespaceEntry struct {
type forwardEntry struct {
Resource string `yaml:"resource"`
Protocol string `yaml:"protocol"`
Alias string `yaml:"alias,omitempty"`
Port int `yaml:"port"`
LocalPort int `yaml:"localPort"`
Alias string `yaml:"alias,omitempty"`
}
// Convert internal types to config package types