Skip to content

Commit

Permalink
Fix goconst linter error
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Bolzhatov committed Oct 21, 2024
1 parent 40feb9e commit 94714c4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions log/masker.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type FieldMasker struct {
Masks []Mask
}

const ignoreCase = `(?i)`

func NewFieldMasker(cfg MaskingRuleConfig) FieldMasker {
fMask := FieldMasker{Field: strings.ToLower(cfg.Field), Masks: make([]Mask, 0, len(cfg.Masks))}

Expand All @@ -30,11 +32,11 @@ func NewFieldMasker(cfg MaskingRuleConfig) FieldMasker {
for _, format := range cfg.Formats {
switch format {
case FieldMaskFormatHTTPHeader:
fMask.Masks = append(fMask.Masks, NewMask(MaskConfig{`(?i)` + cfg.Field + `: .+?\r\n`, cfg.Field + ": ***\r\n"}))
fMask.Masks = append(fMask.Masks, NewMask(MaskConfig{ignoreCase + cfg.Field + `: .+?\r\n`, cfg.Field + ": ***\r\n"}))
case FieldMaskFormatJSON:
fMask.Masks = append(fMask.Masks, NewMask(MaskConfig{`(?i)"` + cfg.Field + `"\s*:\s*".*?[^\\]"`, `"` + cfg.Field + `": "***"`}))
fMask.Masks = append(fMask.Masks, NewMask(MaskConfig{ignoreCase + `"` + cfg.Field + `"\s*:\s*".*?[^\\]"`, `"` + cfg.Field + `": "***"`}))
case FieldMaskFormatURLEncoded:
fMask.Masks = append(fMask.Masks, NewMask(MaskConfig{`(?i)` + cfg.Field + `\s*=\s*[^&\s]+`, cfg.Field + "=***"}))
fMask.Masks = append(fMask.Masks, NewMask(MaskConfig{ignoreCase + cfg.Field + `\s*=\s*[^&\s]+`, cfg.Field + "=***"}))
}
}
return fMask
Expand Down

0 comments on commit 94714c4

Please sign in to comment.