chore: apply go fix modernizations (#4822)
Deploy VitePress site to Pages / build (push) Has been cancelled
Deploy VitePress site to Pages / Deploy (push) Has been cancelled
Push container / Push branches and PRs (push) Has been cancelled
Test / Typecheck (push) Has been cancelled
Test / JavaScript Tests (push) Has been cancelled
Test / Go Tests (push) Has been cancelled
Test / Go Staticcheck (push) Has been cancelled
Test / Integration Tests (push) Has been cancelled

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Amir Raminfar
2026-07-09 10:51:26 -07:00
committed by GitHub
parent 8d810b7a0b
commit bd4651fb0b
17 changed files with 87 additions and 93 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ func (a *simpleAuthContext) CreateToken(username, password string) (string, erro
return "", ErrInvalidCredentials return "", ErrInvalidCredentials
} }
claims := map[string]interface{}{"username": user.Username, "email": user.Email, "name": user.Name, "filter": user.Filter, "roles": user.Roles} claims := map[string]any{"username": user.Username, "email": user.Email, "name": user.Name, "filter": user.Filter, "roles": user.Roles}
jwtauth.SetIssuedNow(claims) jwtauth.SetIssuedNow(claims)
if a.ttl > 0 { if a.ttl > 0 {
+2 -4
View File
@@ -162,9 +162,7 @@ func (ls *logStreamer) startReader(parent context.Context, c container.Container
return return
} }
ls.wg.Add(1) ls.wg.Go(func() {
go func() {
defer ls.wg.Done()
defer func() { defer func() {
ls.mu.Lock() ls.mu.Lock()
delete(ls.readers, key) delete(ls.readers, key)
@@ -172,7 +170,7 @@ func (ls *logStreamer) startReader(parent context.Context, c container.Container
cancel() cancel()
}() }()
ls.runReader(readerCtx, cs, minRank) ls.runReader(readerCtx, cs, minRank)
}() })
} }
// runReader follows logs from a single container and pushes batches directly // runReader follows logs from a single container and pushes batches directly
+1 -2
View File
@@ -117,8 +117,7 @@ func TestEventGenerator_doesNotStallOnSustainedLevellessStream(t *testing.T) {
// maxGroupTimeDelta, every line looks like an orphaned continuation, so the // maxGroupTimeDelta, every line looks like an orphaned continuation, so the
// skip loop buffers forever and the UI shows "no logs". The generator must // skip loop buffers forever and the UI shows "no logs". The generator must
// give up and emit instead. // give up and emit instead.
ctx, cancel := context.WithCancel(context.Background()) ctx := t.Context()
defer cancel()
reader := &steadyLevellessReader{ctx: ctx, base: time.Now(), step: time.Millisecond, delay: time.Millisecond} reader := &steadyLevellessReader{ctx: ctx, base: time.Now(), step: time.Millisecond, delay: time.Millisecond}
// startedAt far in the past so the near-start short-circuit cannot fire // startedAt far in the past so the near-start short-circuit cannot fire
+4 -4
View File
@@ -233,12 +233,12 @@ func ParseContainerFilter(commaValues string) (ContainerLabels, error) {
} }
for val := range strings.SplitSeq(commaValues, ",") { for val := range strings.SplitSeq(commaValues, ",") {
pos := strings.Index(val, "=") before, after, ok := strings.Cut(val, "=")
if pos == -1 { if !ok {
return nil, fmt.Errorf("invalid filter: %s", filter) return nil, fmt.Errorf("invalid filter: %s", filter)
} }
key := val[:pos] key := before
val := val[pos+1:] val := after
filter[key] = append(filter[key], val) filter[key] = append(filter[key], val)
} }
+1 -1
View File
@@ -46,7 +46,7 @@ func newVolumeMonitor(store *ContainerStore) *volumeMonitor {
} }
func (v *volumeMonitor) start(ctx context.Context) { func (v *volumeMonitor) start(ctx context.Context) {
for i := 0; i < volumeWorkerCount; i++ { for range volumeWorkerCount {
go v.worker(ctx) go v.worker(ctx)
} }
} }
+1 -1
View File
@@ -32,7 +32,7 @@ func NewLogReader(r io.Reader, tty bool) *LogReader {
reader: bufio.NewReader(r), reader: bufio.NewReader(r),
tty: tty, tty: tty,
pool: &sync.Pool{ pool: &sync.Pool{
New: func() interface{} { New: func() any {
return bytes.NewBuffer(make([]byte, 0, 4096)) return bytes.NewBuffer(make([]byte, 0, 4096))
}, },
}, },
+4 -10
View File
@@ -6,7 +6,9 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"maps"
"regexp" "regexp"
"slices"
"strings" "strings"
"sync" "sync"
"time" "time"
@@ -154,9 +156,7 @@ func (k *K8sClient) podToContainers(ctx context.Context, pod *corev1.Pod) []cont
// Build labels map with pod labels, namespace, and owner reference // Build labels map with pod labels, namespace, and owner reference
labels := make(map[string]string) labels := make(map[string]string)
for k, v := range pod.Labels { maps.Copy(labels, pod.Labels)
labels[k] = v
}
labels["namespace"] = pod.Namespace labels["namespace"] = pod.Namespace
labels["@k8s.namespace"] = pod.Namespace labels["@k8s.namespace"] = pod.Namespace
@@ -444,13 +444,7 @@ func matchesContainerLabels(labels map[string]string, filters container.Containe
if !ok { if !ok {
return false return false
} }
matched := false matched := slices.Contains(values, value)
for _, expected := range values {
if value == expected {
matched = true
break
}
}
if !matched { if !matched {
return false return false
} }
+1 -1
View File
@@ -41,7 +41,7 @@ type Settings struct {
type Profile struct { type Profile struct {
Settings *Settings `json:"settings,omitempty"` Settings *Settings `json:"settings,omitempty"`
Pinned []string `json:"pinned"` Pinned []string `json:"pinned"`
VisibleKeys []interface{} `json:"visibleKeys,omitempty"` VisibleKeys []any `json:"visibleKeys,omitempty"`
ReleaseSeen string `json:"releaseSeen,omitempty"` ReleaseSeen string `json:"releaseSeen,omitempty"`
CollapsedGroups []string `json:"collapsedGroups"` CollapsedGroups []string `json:"collapsedGroups"`
} }
+1 -1
View File
@@ -54,7 +54,7 @@ func (Args) Version() string {
return Version return Version
} }
func ParseArgs() (Args, interface{}) { func ParseArgs() (Args, any) {
var args Args var args Args
parser := arg.MustParse(&args) parser := arg.MustParse(&args)
+5 -6
View File
@@ -8,16 +8,15 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
func ValidateEnvVars(types ...interface{}) { func ValidateEnvVars(types ...any) {
expectedEnvs := make(map[string]bool) expectedEnvs := make(map[string]bool)
for _, t := range types { for _, t := range types {
typ := reflect.TypeOf(t) typ := reflect.TypeOf(t)
for i := 0; i < typ.NumField(); i++ { for field := range typ.Fields() {
field := typ.Field(i) for tag := range strings.SplitSeq(field.Tag.Get("arg"), ",") {
for _, tag := range strings.Split(field.Tag.Get("arg"), ",") { if after, ok := strings.CutPrefix(tag, "env:"); ok {
if strings.HasPrefix(tag, "env:") { expectedEnvs[after] = true
expectedEnvs[strings.TrimPrefix(tag, "env:")] = true
} }
} }
} }
+9 -9
View File
@@ -34,7 +34,7 @@ func EscapeHTMLValues(logEvent *container.LogEvent) {
case *orderedmap.OrderedMap[string, string]: case *orderedmap.OrderedMap[string, string]:
escapeStringMap(value) escapeStringMap(value)
case map[string]interface{}: case map[string]any:
panic("not implemented") panic("not implemented")
case map[string]string: case map[string]string:
@@ -66,11 +66,11 @@ func escapeAnyMap(orderedMap *orderedmap.OrderedMap[string, any]) {
escapeAnyMap(value) escapeAnyMap(value)
case *orderedmap.OrderedMap[string, string]: case *orderedmap.OrderedMap[string, string]:
escapeStringMap(value) escapeStringMap(value)
case map[string]interface{}: case map[string]any:
escapeMapStringInterface(value) escapeMapStringInterface(value)
case map[string]string: case map[string]string:
escapeStringMapString(value) escapeStringMapString(value)
case []interface{}: case []any:
escapeSlice(value) escapeSlice(value)
orderedMap.Set(pair.Key, value) orderedMap.Set(pair.Key, value)
default: default:
@@ -85,16 +85,16 @@ func escapeStringMap(orderedMap *orderedmap.OrderedMap[string, string]) {
} }
} }
func escapeMapStringInterface(value map[string]interface{}) { func escapeMapStringInterface(value map[string]any) {
for key, val := range value { for key, val := range value {
switch val := val.(type) { switch val := val.(type) {
case string: case string:
value[key] = escapeAndProcessMarkers(val) value[key] = escapeAndProcessMarkers(val)
case map[string]interface{}: case map[string]any:
escapeMapStringInterface(val) escapeMapStringInterface(val)
case map[string]string: case map[string]string:
escapeStringMapString(val) escapeStringMapString(val)
case []interface{}: case []any:
escapeSlice(val) escapeSlice(val)
} }
} }
@@ -106,7 +106,7 @@ func escapeStringMapString(value map[string]string) {
} }
} }
func escapeSlice(slice []interface{}) { func escapeSlice(slice []any) {
for i, val := range slice { for i, val := range slice {
switch val := val.(type) { switch val := val.(type) {
case string: case string:
@@ -115,11 +115,11 @@ func escapeSlice(slice []interface{}) {
escapeAnyMap(val) escapeAnyMap(val)
case *orderedmap.OrderedMap[string, string]: case *orderedmap.OrderedMap[string, string]:
escapeStringMap(val) escapeStringMap(val)
case map[string]interface{}: case map[string]any:
escapeMapStringInterface(val) escapeMapStringInterface(val)
case map[string]string: case map[string]string:
escapeStringMapString(val) escapeStringMapString(val)
case []interface{}: case []any:
escapeSlice(val) escapeSlice(val)
} }
} }
+5 -5
View File
@@ -67,7 +67,7 @@ func (pm *PatternMatcher) MarkInLogEvent(logEvent *container.LogEvent) bool {
case *orderedmap.OrderedMap[string, string]: case *orderedmap.OrderedMap[string, string]:
return pm.markMapString(value) return pm.markMapString(value)
case map[string]interface{}: case map[string]any:
return pm.markMap(value) return pm.markMap(value)
case map[string]string: case map[string]string:
@@ -105,7 +105,7 @@ func (pm *PatternMatcher) markMapAny(orderedMap *orderedmap.OrderedMap[string, a
found = true found = true
} }
case map[string]interface{}: case map[string]any:
if pm.markMap(value) { if pm.markMap(value) {
found = true found = true
} }
@@ -125,7 +125,7 @@ func (pm *PatternMatcher) markMapAny(orderedMap *orderedmap.OrderedMap[string, a
return found return found
} }
func (pm *PatternMatcher) markMap(data map[string]interface{}) bool { func (pm *PatternMatcher) markMap(data map[string]any) bool {
found := false found := false
for key, value := range data { for key, value := range data {
switch value := value.(type) { switch value := value.(type) {
@@ -139,7 +139,7 @@ func (pm *PatternMatcher) markMap(data map[string]interface{}) bool {
found = true found = true
} }
case map[string]interface{}: case map[string]any:
if pm.markMap(value) { if pm.markMap(value) {
found = true found = true
} }
@@ -188,7 +188,7 @@ func (pm *PatternMatcher) markArray(data []any) bool {
if pm.markArray(value) { if pm.markArray(value) {
found = true found = true
} }
case map[string]interface{}: case map[string]any:
if pm.markMap(value) { if pm.markMap(value) {
found = true found = true
} }
+1 -1
View File
@@ -8,7 +8,7 @@ import (
) )
func (h *handler) debugStore(w http.ResponseWriter, r *http.Request) { func (h *handler) debugStore(w http.ResponseWriter, r *http.Request) {
respone := make(map[string]interface{}) respone := make(map[string]any)
respone["hosts"] = h.hostService.Hosts() respone["hosts"] = h.hostService.Hosts()
containers, errors := h.hostService.ListAllContainers(container.ContainerLabels{}) containers, errors := h.hostService.ListAllContainers(container.ContainerLabels{})
respone["containers"] = containers respone["containers"] = containers
+7 -7
View File
@@ -55,7 +55,7 @@ func (h *handler) executeTemplate(w http.ResponseWriter, req *http.Request) {
} }
} }
config := map[string]interface{}{ config := map[string]any{
"base": base, "base": base,
} }
@@ -100,7 +100,7 @@ func (h *handler) executeTemplate(w http.ResponseWriter, req *http.Request) {
config["profile"] = struct{}{} config["profile"] = struct{}{}
} }
data := map[string]interface{}{ data := map[string]any{
"Config": config, "Config": config,
"Dev": h.config.Dev, "Dev": h.config.Dev,
"Manifest": h.readManifest(), "Manifest": h.readManifest(),
@@ -115,7 +115,7 @@ func (h *handler) executeTemplate(w http.ResponseWriter, req *http.Request) {
log.Fatal().Err(err).Msg("Could not read index.html") log.Fatal().Err(err).Msg("Could not read index.html")
} }
tmpl, err := template.New("index.html").Funcs(template.FuncMap{ tmpl, err := template.New("index.html").Funcs(template.FuncMap{
"marshal": func(v interface{}) template.JS { "marshal": func(v any) template.JS {
var p []byte var p []byte
if h.config.Dev { if h.config.Dev {
p, _ = json.MarshalIndent(v, "", " ") p, _ = json.MarshalIndent(v, "", " ")
@@ -136,20 +136,20 @@ func (h *handler) executeTemplate(w http.ResponseWriter, req *http.Request) {
} }
} }
func (h *handler) readManifest() map[string]interface{} { func (h *handler) readManifest() map[string]any {
if h.config.Dev { if h.config.Dev {
return map[string]interface{}{} return map[string]any{}
} else { } else {
file, err := h.content.Open(".vite/manifest.json") file, err := h.content.Open(".vite/manifest.json")
if err != nil { if err != nil {
// this should only happen during test. In production, the file is embedded in the binary and checked in main.go // this should only happen during test. In production, the file is embedded in the binary and checked in main.go
return map[string]interface{}{} return map[string]any{}
} }
bytes, err := io.ReadAll(file) bytes, err := io.ReadAll(file)
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("Could not read .vite/manifest.json") log.Fatal().Err(err).Msg("Could not read .vite/manifest.json")
} }
var manifest map[string]interface{} var manifest map[string]any
err = json.Unmarshal(bytes, &manifest) err = json.Unmarshal(bytes, &manifest)
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("Could not unmarshal .vite/manifest.json") log.Fatal().Err(err).Msg("Could not unmarshal .vite/manifest.json")
+2 -2
View File
@@ -269,7 +269,7 @@ func (h *handler) streamContainerLogs(w http.ResponseWriter, r *http.Request) {
func (h *handler) streamLogsMerged(w http.ResponseWriter, r *http.Request) { func (h *handler) streamLogsMerged(w http.ResponseWriter, r *http.Request) {
ids := make(map[string]bool) ids := make(map[string]bool)
for _, id := range strings.Split(chi.URLParam(r, "ids"), ",") { for id := range strings.SplitSeq(chi.URLParam(r, "ids"), ",") {
ids[id] = true ids[id] = true
} }
@@ -285,7 +285,7 @@ func (h *handler) streamLogsWithLabels(w http.ResponseWriter, r *http.Request) {
labelFilters := make(map[string]string) labelFilters := make(map[string]string)
if labelsParam != "" { if labelsParam != "" {
for _, pair := range strings.Split(labelsParam, ",") { for pair := range strings.SplitSeq(labelsParam, ",") {
parts := strings.SplitN(pair, ":", 2) parts := strings.SplitN(pair, ":", 2)
if len(parts) == 2 { if len(parts) == 2 {
labelFilters[parts[0]] = parts[1] labelFilters[parts[0]] = parts[1]
+9
View File
@@ -0,0 +1,9 @@
import path from "node:path";
export default {
"*.{js,vue,css,ts,html,md}": ["prettier --write"],
"*.go": (files) => {
const dirs = [...new Set(files.map((f) => path.dirname(f)))];
return [`go fix ${dirs.join(" ")}`, `gofmt -w ${files.join(" ")}`];
},
};
-5
View File
@@ -110,11 +110,6 @@
"vue-component-type-helpers": "3.3.6", "vue-component-type-helpers": "3.3.6",
"vue-tsc": "3.3.6" "vue-tsc": "3.3.6"
}, },
"lint-staged": {
"*.{js,vue,css,ts,html,md}": [
"prettier --write"
]
},
"simple-git-hooks": { "simple-git-hooks": {
"pre-commit": "pnpm lint-staged --allow-empty" "pre-commit": "pnpm lint-staged --allow-empty"
} }