go-json-rest:JSON有效负载为空

I'm trying to use go-json-rest to create RESTful APIs

I have this model struct:

type Todo struct {
    id   int
    name string
}

And I am trying to do a POST request to create an object of Todo type:

func CreateTodo(w rest.ResponseWriter, r *rest.Request) {

    body, _ := ioutil.ReadAll(r.Body)
    log.Println("body content is: ", string(body)) // here I can see {"name": "test1"}
    var todo Todo = Todo{}
    err := r.DecodeJsonPayload(&todo) // here the error shows JSON payload is empty
    defer r.Body.Close()

    if err != nil {
        log.Println("error in parsing json")
        rest.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }

    if todo.name == "" {
        rest.Error(w, "todo name is required", 400)
        return
    }
    lock.Lock()

    var nextId int = len(todos)
    //  todos[nextId] = todo
    todo.id = nextId // set its id
    todos = append(todos, todo)
    log.Println("num of todos: ", len(todos))
    lock.Unlock()

    w.WriteJson(&todo)
}

However, in the console of the POSTMAN client, the error shows:

{
  "Error": "JSON payload is empty"
}

I was wondering where might go wrong. Thanks

Edit: This should not be considered a duplicate question, because I am not even trying to use the json package to do marshalling/unmarshalling of JSON object. Instead I am using the rest.Request object (built in go-json-rest) to decode the json parameters as posted from client.

After much digging and search on this problem I found this answer below resolved my issue:

body, _ := ioutil.ReadAll(r.Body) will consume everything from the request body. So after removing this line, the json parsing works!

I was just being silly doing body, _ := ioutil.ReadAll(r.Body) before decoding the JSON parameters without really understanding what ioutil.ReadAll() does to the request body.

As I quoted above in the edited post, ioutil.ReadAll() consumes everything in the request body, leaving nothing for the json decoder to parse. After removing the line body, _ := ioutil.ReadAll(r.Body), the json parsing works as expected.