Skip to content

Commit

Permalink
⬆️ Update json-to-go
Browse files Browse the repository at this point in the history
  • Loading branch information
nkmr-jp committed Oct 28, 2022
1 parent 2af03f3 commit 4c0cf8a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions vendor/json-to-go.js
Expand Up @@ -22,7 +22,7 @@ function jsonToGo(json, typename, flatten = true, example = false, allOmitempty

try
{
data = JSON.parse(json.replace(/:(\s*\d*)\.0/g, ":$1.1")); // hack that forces floats to stay as floats
data = JSON.parse(json.replace(/(:\s*\[?\s*-?\d*)\.0/g, "$1.1")); // hack that forces floats to stay as floats
scope = data;
}
catch (e)
Expand Down Expand Up @@ -62,7 +62,7 @@ function jsonToGo(json, typename, flatten = true, example = false, allOmitempty
else if (sliceType != thisType)
{
sliceType = mostSpecificPossibleGoType(thisType, sliceType);
if (sliceType == "interface{}")
if (sliceType == "any")
break;
}
}
Expand Down Expand Up @@ -130,9 +130,9 @@ function jsonToGo(json, typename, flatten = true, example = false, allOmitempty
}
else {
if (flatten && depth >= 2) {
appender(sliceType || "interface{}");
appender(sliceType || "any");
} else {
append(sliceType || "interface{}");
append(sliceType || "any");
}
}
}
Expand Down Expand Up @@ -316,7 +316,7 @@ function jsonToGo(json, typename, flatten = true, example = false, allOmitempty
function goType(val)
{
if (val === null)
return "interface{}";
return "any";

switch (typeof val)
{
Expand All @@ -342,7 +342,7 @@ function jsonToGo(json, typename, flatten = true, example = false, allOmitempty
return "slice";
return "struct";
default:
return "interface{}";
return "any";
}
}

Expand All @@ -356,7 +356,7 @@ function jsonToGo(json, typename, flatten = true, example = false, allOmitempty
&& typ2.substr(0, 5) == "float")
return typ2;
else
return "interface{}";
return "any";
}

// Proper cases a string according to Go conventions
Expand Down

0 comments on commit 4c0cf8a

Please sign in to comment.