Prepare for storing books

We need a place to store information about the available books. Let's use a simple slice within our books handler.
} -type books struct{} +type books struct { + all []book +} + +type book struct { + Title string `json:"title"` +} func (h *books) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") model := struct { - Message string `json:"message"` + Books []book `json:"books"` }{ - "No books available!", + h.all, } json.NewEncoder(w).Encode(model) }
prev toc next