mirror of
https://github.com/amir20/dozzle.git
synced 2026-01-03 19:45:01 +01:00
feat: allows filters to be set at user level (#3456)
This commit is contained in:
@@ -3,6 +3,7 @@ package docker
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/amir20/dozzle/internal/utils"
|
||||
@@ -44,6 +45,29 @@ type ContainerEvent struct {
|
||||
|
||||
type ContainerFilter map[string][]string
|
||||
|
||||
func ParseContainerFilter(commaValues string) (ContainerFilter, error) {
|
||||
filter := make(ContainerFilter)
|
||||
if commaValues == "" {
|
||||
return filter, nil
|
||||
}
|
||||
|
||||
for _, val := range strings.Split(commaValues, ",") {
|
||||
pos := strings.Index(val, "=")
|
||||
if pos == -1 {
|
||||
return nil, fmt.Errorf("invalid filter: %s", filter)
|
||||
}
|
||||
key := val[:pos]
|
||||
val := val[pos+1:]
|
||||
filter[key] = append(filter[key], val)
|
||||
}
|
||||
|
||||
return filter, nil
|
||||
}
|
||||
|
||||
func (f ContainerFilter) Exists() bool {
|
||||
return len(f) > 0
|
||||
}
|
||||
|
||||
func (f ContainerFilter) asArgs() filters.Args {
|
||||
filterArgs := filters.NewArgs()
|
||||
for key, values := range f {
|
||||
|
||||
Reference in New Issue
Block a user