-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprocess.go
More file actions
71 lines (51 loc) · 1.08 KB
/
process.go
File metadata and controls
71 lines (51 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"io/ioutil"
"log"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"github.com/spf13/viper"
)
func process(filePath string, fi os.FileInfo, err error) error {
if err != nil {
return err
}
if !!fi.IsDir() {
return nil //
}
matched, err := filepath.Match(matchFiles, fi.Name())
if err != nil {
return err
}
if matched {
file, err := ioutil.ReadFile(filePath)
if err != nil {
panic(err)
}
matchExp := regexp.MustCompile(matchString)
for matchExp.MatchString(string(file)) == true {
codeNumber := getCodeNumber()
codeNumber = prefix + codeNumber
newContents := strings.Replace(string(file), matchString, codeNumber, 1)
err = ioutil.WriteFile(filePath, []byte(newContents), 0)
if err != nil {
panic(err)
}
file, err = ioutil.ReadFile(filePath)
if err != nil {
panic(err)
}
}
log.Println("Processed file: " + filePath)
}
return nil
}
func getCodeNumber() string {
isecode := viper.GetInt("LAST_NUMBER") + 1
viper.Set("LAST_NUMBER", isecode)
viper.WriteConfig()
return strconv.Itoa(isecode)
}