Files
cunicu/pkg/log/field.go
Steffen Vogel 3bee839348 fix: Update copyright years
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
2025-01-01 22:45:39 +01:00

31 lines
671 B
Go

// SPDX-FileCopyrightText: 2023-2025 Steffen Vogel <post@steffenvogel.de>
// SPDX-License-Identifier: Apache-2.0
package log
import (
"reflect"
"slices"
"strings"
)
func getFieldName(field reflect.StructField) (string, bool) {
if value := getFirstTagValue(field.Tag, "json", "toml", "mapstructure", "koanf"); value != "" {
parts := strings.Split(value, ",")
return parts[0], slices.Contains(parts, "omitempty")
}
return strings.ToLower(field.Name), true
}
func getFirstTagValue(tag reflect.StructTag, searchTags ...string) string {
for _, searchTag := range searchTags {
if value, ok := tag.Lookup(searchTag); ok {
return value
}
}
return ""
}