-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
47 lines (41 loc) · 1.05 KB
/
config.go
File metadata and controls
47 lines (41 loc) · 1.05 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
package main
import (
"bufio"
"encoding/json"
"fmt"
"os"
)
type grep_step struct {
Title string `json:"title"`
Index int `json:"index"`
Select_Ref string `json:"select_ref"`
GrepPattern string `json:"grep_select_pattern"`
RegexpPattern string `json:"regexp_pattern"`
Output string `step:"output"`
InputFile string `json:"input_file"`
OutputFilenameTemplate string `json:"output_filename_template"`
}
type grep_steps struct {
Steps []grep_step `json:"steps"`
}
func NewConfig(filename string) *grep_steps {
var steps grep_steps
var bytes []byte
mfile, err := os.Open(filename)
if err != nil {
panic(err)
}
scanner := bufio.NewScanner(mfile)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
bytes = append(bytes, scanner.Bytes()...)
}
// The method os.File.Close() is called
// on the os.File object to close the file
mfile.Close()
err = json.Unmarshal(bytes, &steps)
if err != nil {
fmt.Printf("Error %v\n", err)
}
return &steps
}