feat: generate html reports for API testing #74

This commit is contained in:
xucong053
2022-02-07 20:29:10 +08:00
parent 2a81a4a04a
commit 9415a7bb95
16 changed files with 506 additions and 42 deletions

View File

@@ -10,6 +10,7 @@ import (
"math"
"math/rand"
"path/filepath"
"reflect"
"strings"
"time"
@@ -129,3 +130,30 @@ func Dump2YAML(data interface{}, path string) error {
}
return nil
}
func formatValue(raw interface{}) interface{} {
rawValue := reflect.ValueOf(raw)
switch rawValue.Kind() {
case reflect.Map:
m := make(map[string]interface{})
for key, value := range rawValue.Interface().(map[string]interface{}) {
b, _ := json.MarshalIndent(&value, "", " ")
m[key] = string(b)
}
return m
case reflect.Slice:
b, _ := json.MarshalIndent(&raw, "", " ")
return string(b)
default:
return raw
}
}
func FormatResponse(raw interface{}) interface{} {
formattedResponse := make(map[string]interface{})
for key, value := range raw.(map[string]interface{}) {
// convert value to json
formattedResponse[key] = formatValue(value)
}
return formattedResponse
}