gitlab.com/evatix-go/core@v1.3.55/keymk/fixedLegend.go (about) 1 package keymk 2 3 import "strings" 4 5 type fixedLegend struct{} 6 7 func (it fixedLegend) FormatKeyMap( 8 rootName, 9 packageName, 10 groupName, 11 stateName, 12 userName, 13 item string, 14 ) (format string, replacerMap map[string]string) { 15 return LegendChainSample, map[string]string{ 16 "{root}": rootName, 17 "{package}": packageName, 18 "{group}": groupName, 19 "{state}": stateName, 20 "{user}": userName, 21 "{item}": item, 22 } 23 } 24 25 func (it fixedLegend) Compile( 26 isKeepFormatOnEmpty bool, 27 rootName, 28 packageName, 29 groupName, 30 stateName, 31 userName, 32 item string, 33 ) (compiled string) { 34 format, compilingMap := it.FormatKeyMap( 35 rootName, 36 packageName, 37 groupName, 38 stateName, 39 userName, 40 item) 41 42 for searcher, replacer := range compilingMap { 43 if isKeepFormatOnEmpty && replacer == "" { 44 continue 45 } 46 47 format = strings.ReplaceAll( 48 format, 49 searcher, 50 replacer) 51 } 52 53 return format 54 } 55 56 func (it fixedLegend) CompileKeepFormatOnEmpty( 57 rootName, 58 packageName, 59 groupName, 60 stateName, 61 userName, 62 item string, 63 ) (compiled string) { 64 return it.Compile( 65 true, 66 rootName, 67 packageName, 68 groupName, 69 stateName, 70 userName, 71 item) 72 }