Skip to content

Commit

Permalink
CI: Enable and fix some checks - Pt1 (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
DownerCase authored Dec 16, 2024
1 parent 7c33da2 commit 155a76e
Show file tree
Hide file tree
Showing 48 changed files with 574 additions and 549 deletions.
28 changes: 14 additions & 14 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ linters:
disable:
- exportloopref # Deprecated
- execinquery # Deprecated
- exhaustruct # Very noisy, hard to disable when want zero values
- forcetypeassert # If its wrong, we want to know
- nlreturn # Not desired
- gci
- gocritic
- gofumpt
- forbidigo
- godot
- godox
- gomnd
- ireturn
- exhaustruct
- gochecknoglobals
- gosec
- mnd
- forcetypeassert
- nlreturn
- nonamedreturns
- paralleltest
- predeclared
Expand All @@ -23,17 +21,19 @@ linters:
- varnamelen
- wrapcheck
- wsl
- err113
- stylecheck
- gochecknoglobals
- depguard
- cyclop
- whitespace
- revive
- goimports
- gosec
- protogetter
- funlen
- unparam
- exhaustive
- inamedparam

linters-settings:
ireturn:
allow:
- tea.Model
- error
- stdlib
- empty
- generic
16 changes: 11 additions & 5 deletions cmd/monitor/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ package main

import (
"errors"
"fmt"

"github.com/DownerCase/ecal-go/ecal/monitoring"
"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
)

var (
errNoTopic = errors.New("no topic")
errEmptyTable = errors.New("table empty")
)

func NewTable(columns []table.Column) table.Model {
return table.New(
table.WithHeight(8),
Expand Down Expand Up @@ -46,12 +52,12 @@ func getTopicMonitoring(topicType topicType) []monitoring.TopicMon {
return nil
}

func getTopicFromId(topicType topicType, id string) (monitoring.TopicMon, error) {
topic_list := getTopicMonitoring(topicType)
for _, topic := range topic_list {
if topic.Topic_id == id {
func getTopicFromID(topicType topicType, id string) (monitoring.TopicMon, error) {
topicList := getTopicMonitoring(topicType)
for _, topic := range topicList {
if topic.TopicID == id {
return topic, nil
}
}
return monitoring.TopicMon{}, errors.New("Unable to find topic")
return monitoring.TopicMon{}, fmt.Errorf("[getTopicFromId]: %w", errNoTopic)
}
12 changes: 6 additions & 6 deletions cmd/monitor/config_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ import (
tea "github.com/charmbracelet/bubbletea"
)

type model_config struct {
type modelConfig struct {
viewport viewport.Model
}

func NewConfigModel() *model_config {
func NewConfigModel() *modelConfig {
viewport := viewport.New(85, 10)
viewport.SetContent(ecal.GetConfig())
viewport.Style = baseStyle
return &model_config{
return &modelConfig{
viewport: viewport,
}
}

func (m *model_config) Refresh() {}
func (m *modelConfig) Refresh() {}

func (m *model_config) Update(msg tea.Msg) (cmd tea.Cmd) {
func (m *modelConfig) Update(msg tea.Msg) (cmd tea.Cmd) {
m.viewport, cmd = m.viewport.Update(msg)
return cmd
}

func (m *model_config) View() string {
func (m *modelConfig) View() string {
return m.viewport.View()
}
18 changes: 9 additions & 9 deletions cmd/monitor/hosts_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
tea "github.com/charmbracelet/bubbletea"
)

type model_hosts struct {
type modelHosts struct {
table table.Model
}

func NewHostsModel() *model_hosts {
func NewHostsModel() *modelHosts {
columns := []table.Column{
{Title: "Host", Width: 28},
{Title: "Processes", Width: 9},
Expand All @@ -22,21 +22,21 @@ func NewHostsModel() *model_hosts {
{Title: "Clients", Width: 7},
}

return &model_hosts{
return &modelHosts{
table: NewTable(columns),
}
}

func (m *model_hosts) Update(msg tea.Msg) tea.Cmd {
func (m *modelHosts) Update(msg tea.Msg) tea.Cmd {
m.updateTable(nil)
return nil
}

func (m *model_hosts) View() string {
func (m *modelHosts) View() string {
return baseStyle.Render(m.table.View()) + "\n" + m.table.HelpView()
}

func (m *model_hosts) Refresh() {
func (m *modelHosts) Refresh() {
m.updateTable(nil)
}

Expand All @@ -48,7 +48,7 @@ type hostInfo struct {
Processes int
}

func (m *model_hosts) updateTable(msg tea.Msg) {
func (m *modelHosts) updateTable(msg tea.Msg) {
mon := monitoring.GetMonitoring(monitoring.MonitorAll)

hosts := make(map[string]hostInfo)
Expand All @@ -73,9 +73,9 @@ func (m *model_hosts) updateTable(msg tea.Msg) {
hosts[server.HostName] = host
}
for _, proc := range mon.Processes {
host := hosts[proc.Host_name]
host := hosts[proc.HostName]
host.Processes += 1
hosts[proc.Host_name] = host
hosts[proc.HostName] = host
}

m.table.SetRows(hostsToRows(hosts))
Expand Down
54 changes: 27 additions & 27 deletions cmd/monitor/log_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import (
type LoggingPage int

const (
subpage_logging_main LoggingPage = iota
subpage_logging_detailed
subpageLoggingMain LoggingPage = iota
subpageLoggingDetailed
)

type logsKeyMap struct {
table.KeyMap
Clear key.Binding
}

type model_logs struct {
table_logs table.Model
subpage LoggingPage
help help.Model
keymap logsKeyMap
type modelLogs struct {
table table.Model
subpage LoggingPage
help help.Model
keymap logsKeyMap
// model_detailed
}

Expand All @@ -48,78 +48,78 @@ func (km logsKeyMap) FullHelp() [][]key.Binding {
return append([][]key.Binding{{km.Clear}}, km.KeyMap.FullHelp()...)
}

func NewLogsModel() *model_logs {
func NewLogsModel() *modelLogs {
columns := []table.Column{
{Title: "Time", Width: 10},
{Title: "Level", Width: 6},
{Title: "Unit", Width: 15},
{Title: "Message", Width: 46},
}

return &model_logs{
table_logs: NewTable(columns),
subpage: subpage_logging_main,
help: help.New(),
keymap: newLogsKeyMap(),
return &modelLogs{
table: NewTable(columns),
subpage: subpageLoggingMain,
help: help.New(),
keymap: newLogsKeyMap(),
}
}

func (m *model_logs) Update(msg tea.Msg) tea.Cmd {
func (m *modelLogs) Update(msg tea.Msg) tea.Cmd {
var cmd tea.Cmd

switch m.subpage {
case subpage_logging_main:
case subpageLoggingMain:
switch msg := msg.(type) {
case tea.KeyMsg:
switch {
case key.Matches(msg, m.keymap.Clear):
m.table_logs.SetRows([]table.Row{})
m.table.SetRows([]table.Row{})
m.updateTable(nil)
default:
m.updateTable(msg)
}
}
case subpage_logging_detailed:
case subpageLoggingDetailed:
// cmd = m.model_detailed.Update(msg)
}
return cmd
}

func (m *model_logs) View() string {
func (m *modelLogs) View() string {
switch m.subpage {
case subpage_logging_main:
return baseStyle.Render(m.table_logs.View()) + "\n" + m.help.View(m.keymap)
case subpage_logging_detailed:
case subpageLoggingMain:
return baseStyle.Render(m.table.View()) + "\n" + m.help.View(m.keymap)
case subpageLoggingDetailed:
// return m.model_detailed.View()
}
return "Invalid page"
}

func (m *model_logs) Refresh() {
func (m *modelLogs) Refresh() {
switch m.subpage {
case subpage_logging_detailed:
case subpageLoggingDetailed:
// m.model_detailed.Refresh()
default:
m.updateTable(nil)
}
}

func (m *model_logs) updateTable(msg tea.Msg) {
func (m *modelLogs) updateTable(msg tea.Msg) {
rows := []table.Row{}
logs := logging.GetLogging().Messages

for _, log := range logs {
rows = append(rows, logToRow(log))
}
m.table_logs.SetRows(append(m.table_logs.Rows(), rows...))
m.table_logs, _ = m.table_logs.Update(msg)
m.table.SetRows(append(m.table.Rows(), rows...))
m.table, _ = m.table.Update(msg)
}

func logToRow(log logging.LogMessage) table.Row {
return []string{
time.UnixMicro(log.Time).Format(time.TimeOnly),
log.Level.String(),
log.Unit_name,
log.UnitName,
log.Content,
}
}
2 changes: 1 addition & 1 deletion cmd/monitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func main() {
ecal.Initialize(
ecal.NewConfig(ecal.WithLoggingReceive(true)),
"Go Monitor",
ecal.C_Subscriber|ecal.C_Monitoring|ecal.C_Logging|ecal.C_Service,
ecal.CSubscriber|ecal.CMonitoring|ecal.CLogging|ecal.CService,
)
defer ecal.Finalize() // Shutdown eCAL at the end of the program
logging.SetConsoleFilter(logging.LevelAll)
Expand Down
Loading

0 comments on commit 155a76e

Please sign in to comment.