github.com/Rookout/GoSDK@v0.1.48/pkg/sanitize.go (about) 1 package pkg 2 3 import ( 4 "reflect" 5 "strings" 6 7 "github.com/Rookout/GoSDK/pkg/config" 8 ) 9 10 var sanitizeBlacklist = map[string]struct{}{"Labels": {}} 11 12 func isBlacklisted(str string) bool { 13 _, ok := sanitizeBlacklist[str] 14 return ok 15 } 16 17 func Sanitize(obj *config.RookOptions) { 18 fields := reflect.TypeOf(*obj) 19 value := reflect.ValueOf(obj) 20 for i := 0; i < fields.NumField(); i++ { 21 field := fields.Field(i) 22 if field.Type.Name() == "string" && value.Elem().Field(i).CanSet() && !isBlacklisted(field.Name) { 23 value.Elem().Field(i).SetString(sanitizeString(field.Name, value.Elem().Field(i).String())) 24 } 25 } 26 } 27 28 func sanitizeString(name, value string) string { 29 if isBlacklisted(name) { 30 return value 31 } 32 33 return strings.Trim(value, " \r\n\t/") 34 }