@@ -208,7 +208,7 @@ func renderTemplate(data interface{}, tmpl string) (bytes.Buffer, error) {
208
208
return buffer , nil
209
209
}
210
210
211
- func replaceFragmentInFile (output , findData , newData , pattern string ) (bool , error ) {
211
+ func replaceFragmentInFile (output , findData , newData string , pattern * regexp. Regexp ) (bool , error ) {
212
212
content , err := os .ReadFile (output )
213
213
if err != nil {
214
214
return false , fmt .Errorf ("read file err: %w" , err )
@@ -246,16 +246,12 @@ func replaceFragmentInFile(output, findData, newData, pattern string) (bool, err
246
246
}
247
247
248
248
// extractFragments returned array with coordinates start and end text
249
- func extractFragments (pattern string , lines []string ) ([][2 ]int , error ) {
249
+ func extractFragments (re * regexp. Regexp , lines []string ) ([][2 ]int , error ) {
250
250
var (
251
251
reFragments [][2 ]int
252
252
start = - 1
253
253
)
254
254
255
- re , err := regexp .Compile (pattern )
256
- if err != nil {
257
- return nil , fmt .Errorf ("regexp error: %w" , err )
258
- }
259
255
for i , line := range lines {
260
256
if re .MatchString (line ) {
261
257
if start != - 1 {
@@ -270,7 +266,7 @@ func extractFragments(pattern string, lines []string) ([][2]int, error) {
270
266
}
271
267
272
268
if len (reFragments ) == 0 {
273
- return nil , fmt .Errorf ("no reFragments found with pattern: %s" , pattern )
269
+ return nil , fmt .Errorf ("no reFragments found with pattern" )
274
270
}
275
271
276
272
var ff [][2 ]int
@@ -291,7 +287,7 @@ func extractFragments(pattern string, lines []string) ([][2]int, error) {
291
287
return ff , nil
292
288
}
293
289
294
- func UpdateFile (data interface {}, output , tmpl , pattern string ) (bool , error ) {
290
+ func UpdateFile (data interface {}, output , tmpl string , pattern * regexp. Regexp ) (bool , error ) {
295
291
buffer , err := renderTemplate (data , tmpl )
296
292
if err != nil {
297
293
return false , fmt .Errorf ("generating data error: %w" , err )
0 commit comments