mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-27 03:21:09 +01:00
v0.26.0
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -11,7 +12,7 @@ import (
|
||||
strutils "github.com/yusing/goutils/strings"
|
||||
)
|
||||
|
||||
var ErrInvalidLabel = gperr.New("invalid label")
|
||||
var ErrInvalidLabel = errors.New("invalid label")
|
||||
|
||||
const nsProxyDot = NSProxy + "."
|
||||
|
||||
@@ -23,7 +24,7 @@ var refPrefixes = func() []string {
|
||||
return prefixes
|
||||
}()
|
||||
|
||||
func ParseLabels(labels map[string]string, aliases ...string) (types.LabelMap, gperr.Error) {
|
||||
func ParseLabels(labels map[string]string, aliases ...string) (types.LabelMap, error) {
|
||||
nestedMap := make(types.LabelMap)
|
||||
errs := gperr.NewBuilder("labels error")
|
||||
|
||||
@@ -35,7 +36,7 @@ func ParseLabels(labels map[string]string, aliases ...string) (types.LabelMap, g
|
||||
continue
|
||||
}
|
||||
if len(parts) == 1 {
|
||||
errs.Add(ErrInvalidLabel.Subject(lbl))
|
||||
errs.AddSubject(ErrInvalidLabel, lbl)
|
||||
continue
|
||||
}
|
||||
parts = parts[1:]
|
||||
@@ -53,7 +54,7 @@ func ParseLabels(labels map[string]string, aliases ...string) (types.LabelMap, g
|
||||
// Move deeper into the nested map
|
||||
m, ok := currentMap[k].(types.LabelMap)
|
||||
if !ok && currentMap[k] != "" {
|
||||
errs.Add(gperr.Errorf("expect mapping, got %T", currentMap[k]).Subject(lbl))
|
||||
errs.AddSubject(fmt.Errorf("expect mapping, got %T", currentMap[k]), lbl)
|
||||
continue
|
||||
} else if !ok {
|
||||
m = make(types.LabelMap)
|
||||
@@ -82,15 +83,7 @@ func ExpandWildcard(labels map[string]string, aliases ...string) {
|
||||
}
|
||||
// lbl is "proxy.X..." where X is alias or wildcard
|
||||
rest := lbl[len(nsProxyDot):] // "X..." or "X.suffix"
|
||||
dotIdx := strings.IndexByte(rest, '.')
|
||||
var alias, suffix string
|
||||
if dotIdx == -1 {
|
||||
alias = rest
|
||||
} else {
|
||||
alias = rest[:dotIdx]
|
||||
suffix = rest[dotIdx+1:]
|
||||
}
|
||||
|
||||
alias, suffix, _ := strings.Cut(rest, ".")
|
||||
if alias == WildcardAlias {
|
||||
delete(labels, lbl)
|
||||
if suffix == "" || strings.Count(value, "\n") > 1 {
|
||||
@@ -120,15 +113,10 @@ func ExpandWildcard(labels map[string]string, aliases ...string) {
|
||||
continue
|
||||
}
|
||||
rest := lbl[len(nsProxyDot):]
|
||||
dotIdx := strings.IndexByte(rest, '.')
|
||||
if dotIdx == -1 {
|
||||
alias, suffix, ok := strings.Cut(rest, ".")
|
||||
if !ok || alias == "" || alias[0] == '#' {
|
||||
continue
|
||||
}
|
||||
alias := rest[:dotIdx]
|
||||
if alias[0] == '#' {
|
||||
continue
|
||||
}
|
||||
suffix := rest[dotIdx+1:]
|
||||
|
||||
idx, known := aliasSet[alias]
|
||||
if !known {
|
||||
|
||||
Reference in New Issue
Block a user