forked from mrichman/hargo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.go
More file actions
35 lines (31 loc) · 762 Bytes
/
validate.go
File metadata and controls
35 lines (31 loc) · 762 Bytes
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
package hargo
import (
"bufio"
"encoding/json"
"fmt"
"os"
log "github.com/sirupsen/logrus"
)
// Validate validates the format of a .har file
func Validate(r *bufio.Reader) (bool, error) {
dec := json.NewDecoder(r)
var har Har
err := dec.Decode(&har)
if err != nil {
log.Error(err)
if ute, ok := err.(*json.UnmarshalTypeError); ok {
log.Errorf("UnmarshalTypeError Value: %v - Type: %v - Offset: %v\n", ute.Value, ute.Type, ute.Offset)
} else if se, ok := err.(*json.SyntaxError); ok {
log.Errorf("SyntaxError %v - Offset: %v\n", err, se.Offset)
} else {
log.Error("Other error: ", err)
}
os.Exit(-2)
} else {
if har.Log.Version == "1.2" {
fmt.Println("Valid HAR file! 😊")
return true, nil
}
}
return false, nil
}