Firstly, as was commented, are you sure you cannot use the go/build package and not run the go list ?
I would not use println (or fmt.Println ) inside the HTTP handlers. It is much better to use log.Println and / or get an error in ResponseWriter . It is also recommended that you make a call to ListenAndServe using log.Fatal .
When printing / registering error values, you can simply use err , you do not need to have err.Error() .
In addition, when you really want to do something more detailed than just reporting / logging an error message, you can see its type and other information. For example, log.Printf("verbose error info: %#v", err) gives:
&json.SyntaxError{msg:"invalid character ',' looking for beginning of value", Offset:0}
I tried this because I know that the json package returns various types of errors with additional information, and I was hoping the offset value would be useful. If that were the case, perhaps it would be helpful:
if err := json.Compact(…) { if err != nil { log.Println("json.Compact:", err) if serr, ok := err.(*json.SyntaxError); ok { log.Println("Occurred at offset:", serr.Offset)
But a zero offset is not useful :(
So, although this does not identify you, I hope this can help you in your further investigation.
Edit:
So by adding:
log.Println("Write file:", ioutil.WriteFile("data.json", buff.Bytes(), 0600))
to the above error handling block, I then ran JSON authentication in the resulting file, and it identified this part:
"XTestImports": [ "io", "log", "net" ] },,{ "Dir": "/usr/local/go/src/mime", "ImportPath": "mime", "Name": "mime",
Pay attention to double ,, .
This should tell you that there is an error in your code. But if not, you need to skip empty entries, either when processing tJ , or when creating it. Later it is better and simply includes:
if len(newj) > 0 { myObj.J = append(myObj.J, newj) }
(where btw you do not check for errors from json.Unmarshal so that it does not clear if it should be empty or if it is empty due to a previous error. Never ignore the error returns!)