From f65d8925aeb151a71f2ae36ccd115377559b88d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Celal=20Emre=20=C3=87i=C3=A7ek?= Date: Wed, 31 Jul 2019 13:27:36 +0300 Subject: [PATCH] Fix type conversion error when no validation error is present. If validation succeeds you get an error like "interface {} is []interface {}, not []map[string]interface {}", to fix this I did a type check on the variable jsArray and returned the expected result based on that. --- cmd/validate.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/validate.go b/cmd/validate.go index 5dff8f2..0cd6b03 100644 --- a/cmd/validate.go +++ b/cmd/validate.go @@ -256,7 +256,17 @@ func fetchResult(vm *otto.Otto) ([]map[string]interface{}, error) { return nil, err } - result := jsArray.([]map[string]interface{}) + var result []map[string]interface{} + + switch v := jsArray.(type) { + default: + log.Fatalf("unexpected type: %T", v) + case []interface{}: + result = make([]map[string]interface{}, 0) + case []map[string]interface{}: + result = jsArray.([]map[string]interface{}) + } + return result, nil }