@@ -17,7 +17,7 @@ import (
1717 "gopkg.in/yaml.v3"
1818)
1919
20- var cache map [string ]interface {} //nolint:gochecknoglobals
20+ var cache map [string ]any //nolint:gochecknoglobals
2121
2222func errorExit (msg string ) {
2323 fmt .Fprintf (os .Stderr , "ERROR: %v\n " , msg )
@@ -39,7 +39,7 @@ func expandRef(refValue string, absPath string, prefix string) string {
3939 filePath := path .Join (absPath , words [0 ])
4040 keyPath := words [1 ]
4141
42- m , ok := cache [filePath ].(map [string ]interface {} )
42+ m , ok := cache [filePath ].(map [string ]any )
4343 if ! ok {
4444 fileHandle , err := os .Open (filePath )
4545 if err != nil {
@@ -48,11 +48,12 @@ func expandRef(refValue string, absPath string, prefix string) string {
4848 defer fileHandle .Close ()
4949
5050 fileScanner := bufio .NewScanner (fileHandle )
51- value := ""
51+ sb := strings. Builder {}
5252 for fileScanner .Scan () {
53- value += fileScanner .Text () + "\n "
53+ sb .WriteString (fileScanner .Text ())
54+ sb .WriteString ("\n " )
5455 }
55-
56+ value := sb . String ()
5657 err = yaml .Unmarshal ([]byte (value ), & m )
5758 if err != nil {
5859 fmt .Println (refValue ) //nolint:forbidigo
@@ -61,9 +62,9 @@ func expandRef(refValue string, absPath string, prefix string) string {
6162 }
6263 cache [filePath ] = m
6364 }
64- retVal := make (map [string ]interface {} )
65+ retVal := make (map [string ]any )
6566 if m [keyPath [1 :]] != nil {
66- retVal = m [keyPath [1 :]].(map [string ]interface {} )
67+ retVal = m [keyPath [1 :]].(map [string ]any )
6768 } else {
6869 fmt .Println (refValue ) //nolint:forbidigo
6970 fmt .Println (keyPath ) //nolint:forbidigo
@@ -83,17 +84,18 @@ func expandRef(refValue string, absPath string, prefix string) string {
8384
8485 var indentedRetValStr string
8586 var indentedLine string
86- for _ , line := range strings .Split (retValStr , "\n " ) {
87+ for line := range strings .SplitSeq (retValStr , "\n " ) {
8788 if strings .TrimSpace (line ) != "" {
8889 indentedLine = prefix + "" + line + "\n "
89- indentedRetValStr += indentedLine
90+ indentedRetValStr += indentedLine //nolint: perfsprint
9091 }
9192 }
9293
9394 return indentedRetValStr [:len (indentedRetValStr )- 1 ]
9495}
9596
96- func main () { //nolint:gocognit
97+ //nolint:gocognit,modernize,perfsprint
98+ func main () {
9799 inputFilePtr := flag .String ("file" , "" , "Source file" )
98100
99101 flag .Parse ()
@@ -106,7 +108,7 @@ func main() { //nolint:gocognit
106108 errorExit ("File " + * inputFilePtr + " does not exist" )
107109 }
108110
109- cache = make (map [string ]interface {} )
111+ cache = make (map [string ]any )
110112
111113 absPath := filepath .Dir (* inputFilePtr )
112114 fileHandle , err := os .Open (* inputFilePtr )
@@ -166,7 +168,7 @@ func main() { //nolint:gocognit
166168
167169 b , _ := yaml .Marshal (& ts )
168170
169- for _ , line := range strings .Split (strings .TrimRight (string (b ), "\n " ), "\n " ) {
171+ for line := range strings .SplitSeq (strings .TrimRight (string (b ), "\n " ), "\n " ) {
170172 result .WriteString (" " + line + "\n " )
171173 }
172174 result .WriteString ("security:" )
0 commit comments