Closed david50407 closed 8 years ago
After using the code below to test actions of json.Marshal
and json.Unmarshal
:
package main
import (
"encoding/json"
"fmt"
)
type Foo struct {
Apple string `json:"field1"`
Banana string `json:"field2"`
}
func main() {
var f Foo
str := `{ "Apple": "app", "field2": "ban" }`
json.Unmarshal([]byte(str), &f)
fmt.Println(f)
s, err := json.Marshal(f)
if err != nil {
fmt.Println("err")
}
fmt.Println(string(s))
}
We can found that the output is
{ ban}
{"field1":"","field2":"ban"}
It means when we set the tag for json field name, json.Unmarshal
will decode by the name we set.
So, the struct defination here https://github.com/codetainerapp/codetainer/blob/0cf7cdf084ab2d28a04b3c8329782618823c480a/models.go#L375 cause losing the file info when we unmarshal the file list from util/files
here https://github.com/codetainerapp/codetainer/blob/0cf7cdf084ab2d28a04b3c8329782618823c480a/models.go#L396 .
wonderful! Thank you for this fix.
When I execute
/codetainer/utils/files -s /
inside the contianer, it returns correct answer, as the screenshot below:BUT, when I list files by codetainer API, it returns only with correct filename but wrong file info (is_dir, is_link, modified_time, etc.), as the screenshot shown below: