diff options
Diffstat (limited to 'config/columns.go')
-rw-r--r-- | config/columns.go | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/config/columns.go b/config/columns.go index 55efa2a7..e1389bc0 100644 --- a/config/columns.go +++ b/config/columns.go @@ -2,6 +2,7 @@ package config import ( "bytes" + "crypto/sha256" "fmt" "reflect" "regexp" @@ -113,7 +114,7 @@ func ParseColumnDefs(key *ini.Key, section *ini.Section) ([]*ColumnDef, error) { columns = append(columns, c) } if len(columns) == 0 { - return nil, fmt.Errorf("%s cannot be empty", key.Name()) + return nil, nil } return columns, nil } @@ -156,3 +157,15 @@ func ColumnDefsToIni(defs []*ColumnDef, keyName string) string { return s.String() } + +var templateFieldNameRe = regexp.MustCompile(`\{\{\.?(\w+)\}\}`) + +func columnNameFromTemplate(s string) string { + match := templateFieldNameRe.FindStringSubmatch(s) + if match == nil { + h := sha256.New() + h.Write([]byte(s)) + return fmt.Sprintf("%x", h.Sum(nil)[:3]) + } + return strings.ReplaceAll(strings.ToLower(match[1]), "info", "") +} |