-
Notifications
You must be signed in to change notification settings - Fork 1
/
json_processor.go
65 lines (55 loc) · 1.1 KB
/
json_processor.go
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
package main
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"reflect"
)
var respMap RespMap
func ParseMockJson(file string) error {
jsonFile, err := os.Open(filepath.Clean(file))
if err != nil {
return err
}
fmt.Println("✔ Successfully opened:", file)
defer func(jsonFile *os.File) {
err := jsonFile.Close()
if err != nil {
log.Fatal(err)
}
}(jsonFile)
byteValue, _ := ioutil.ReadAll(jsonFile)
err = json.Unmarshal(byteValue, &respMap)
if err != nil {
return err
}
fmt.Println("✔ Successfully parsed:", file)
if e.Verbose >= 3 {
fmt.Printf("] %+v\n", respMap)
}
return nil
}
func VerifyMockJson() error {
return nil
}
func checkFieldPresent(i interface{}, key, fName string) error {
dict := reflect.ValueOf(i)
val := dict.MapIndex(reflect.ValueOf(fName))
if val == reflect.ValueOf(nil) {
return errors.New(fmt.Sprintf("Missing `%v` field in %v", fName, key))
}
return nil
}
func printPaths() {
if e.Verbose < 1 {
return
}
fmt.Println("Available paths: ")
for _, k := range respMap {
fmt.Println("=>", k.HTTPRequest.Path)
}
}