mirror of
https://github.com/lukaszraczylo/kportal.git
synced 2026-07-10 06:52:00 +00:00
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:
+20
-2
@@ -1,3 +1,21 @@
|
||||
// Package events provides a publish-subscribe event bus for decoupled
|
||||
// communication between kportal components. Events are typed and carry
|
||||
// contextual data about forward lifecycle, health status, and configuration
|
||||
// changes.
|
||||
//
|
||||
// Event types include:
|
||||
// - Forward lifecycle: starting, connected, disconnected, reconnecting, stopped, error
|
||||
// - Health: status_changed, stale
|
||||
// - Watchdog: worker_hung
|
||||
// - Config: reloaded
|
||||
//
|
||||
// Basic usage:
|
||||
//
|
||||
// bus := events.NewBus()
|
||||
// bus.Subscribe(events.EventForwardConnected, func(e events.Event) {
|
||||
// fmt.Printf("Forward %s connected\n", e.ForwardID)
|
||||
// })
|
||||
// bus.Publish(events.Event{Type: events.EventForwardConnected, ForwardID: "..."})
|
||||
package events
|
||||
|
||||
import (
|
||||
@@ -29,9 +47,9 @@ const (
|
||||
|
||||
// Event represents a system event
|
||||
type Event struct {
|
||||
Data map[string]interface{}
|
||||
Type EventType
|
||||
ForwardID string
|
||||
Data map[string]interface{}
|
||||
}
|
||||
|
||||
// Handler is a function that handles events
|
||||
@@ -39,8 +57,8 @@ type Handler func(event Event)
|
||||
|
||||
// Bus is a simple event bus for decoupled communication between components
|
||||
type Bus struct {
|
||||
mu sync.RWMutex
|
||||
handlers map[EventType][]Handler
|
||||
mu sync.RWMutex
|
||||
closed bool
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user