fix unused key warnings in routes (#3711)

This commit is contained in:
Denis Mishin 2022-10-28 14:59:43 -04:00 committed by GitHub
parent 3f9dfbef76
commit d8f4355f66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,6 +11,7 @@ import (
"os"
"path/filepath"
"reflect"
"regexp"
"strings"
"time"
@ -403,10 +404,15 @@ func optionsFromViper(configFile string) (*Options, error) {
return o, nil
}
var (
// policy's embedded protobuf structs are decoded by separate hook and are unknown to mapstructure
routesEmbeddedFieldsRe = regexp.MustCompile(`(routes|policy)\[\.*`)
)
func checkUnusedConfigFields(configFile string, unused []string) {
keys := make([]string, 0, len(unused))
for _, k := range unused {
if !strings.HasPrefix(k, "policy[") { // policy's embedded protobuf structs are decoded by separate hook and are unknown to mapstructure
if !routesEmbeddedFieldsRe.MatchString(k) {
keys = append(keys, k)
}
}