func (c *Controller) post(w http.ResponseWriter, r *http.Request,
	_ httprouter.Params) {

	// Read request body's json payload into buffer.
	b, err := ioutil.ReadAll(r.Body)
	todo, err := decode(b)
	if err != nil {
		http.Error(w, err.Error(), 500)
	}

	// Use the day (url path) + creation time as key.
	key := fmt.Sprintf("%s/%s", r.URL, todo.Created.Format(time.RFC3339Nano))

	// Put key/buffer into todos bucket.
	if err := c.todos.Put([]byte(key), b); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	if verbose {
		log.Printf("server: %s: %v", key, todo.Task)
	}

	w.Header().Set("Content-Type", "text/plain")
	fmt.Fprintf(w, "put todo for %s: %s\n", key, todo)
}
// post handles post requests to create a daily todo item.
post handles post requests to create a daily todo item.
// post handles post requests to create a daily todo item .
func (c *Controller) post(w http.ResponseWriter, r *http.Request,
	_ httprouter.Params) {
	b, err := ioutil.ReadAll(r.Body)
	todo, err := decode(b)
	if err != nil {
		http.Error(w, err.Error(), 500)
	}
	key := fmt.Sprintf("%s/%s", r.URL, todo.Created.Format(time.RFC3339Nano))
	if err := c.todos.Put([]byte(key), b); err != nil {
		http.Error(w, err.Error(), 500)
		return
	}
	if verbose {
		log.Printf("server: %s: %v", key, todo.Task)
	}
	w.Header().Set("Content-Type", "text/plain")
	fmt.Fprintf(w, "put todo for %s: %s\n", key, todo)
}
func ( c * Controller ) post ( w http . ResponseWriter , r * http . Request , _ httprouter . Params ) { b , err := ioutil . ReadAll ( r . Body ) todo , err := decode ( b ) if err != nil { http . Error ( w , err . Error ( ) , 500 ) } key := fmt . Sprintf ( " " , r . URL , todo . Created . Format ( time . RFC3339Nano ) ) if err := c . todos . Put ( [ ] byte ( key ) , b ) ; err != nil { http . Error ( w , err . Error ( ) , 500 ) return } if verbose { log . Printf ( " " , key , todo . Task ) } w . Header ( ) . Set ( " " , " " ) fmt . Fprintf ( w , " \n " , key , todo ) }
post handles post requests to create a daily todo item.
post handles post requests to create a daily todo item .
// Read request body's json payload into buffer. // Use the day (url path) + creation time as key. // Put key/buffer into todos bucket.