Copy the code below to grocery.go and list.html files, both saved in the same directory. Then fill in the missing code in both files. When a browser visits http://localhost:8080/fruit, your app should respond with this HTML (the spacing doesn’t have to match):       apples     oranges     pears   And when a browser visits http://localhost:8080/meat, your app should respond with this HTML:       chicken     beef     lamb   Try running your finished app, and visit the above URLs in your browser! grocery.go package main import (     "html/template"     "log"     "net/http" ) func check(err error) {     if err != nil {         log.Fatal(err)     } } func writeList(writer http.ResponseWriter, list []string) {     // YOUR CODE HERE: Use the template library to parse the contents     // of the "list.html" file. You'll get a template value and an     // error value.     // Pass the error value to the "check" function.     // Now call the "Execute" method on the template. It should write     // its output to the "writer" parameter, and it should use the     // "list" parameter as its data value.     // You'll get another error value back from "Execute", which     // should be passed to "check". } func fruitHandler(writer http.ResponseWriter, request *http.Request) {     writeList(writer, []string{"apples", "oranges", "pears"}) } func meatHandler(writer http.ResponseWriter, request *http.Request) {     writeList(writer, []string{"chicken", "beef", "lamb"}) } func main() {     http.HandleFunc("/fruit", fruitHandler)     http.HandleFunc("/meat", meatHandler)     err := http.ListenAndServe("localhost:8080", nil)     log.Fatal(err) } list.html

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Copy the code below to grocery.go and list.html files, both saved in the same directory. Then fill in the missing code in both files.
When a browser visits http://localhost:8080/fruit, your app should respond with this HTML (the spacing doesn’t have to match):
<html>
  <ul>
    <li>apples</li>
    <li>oranges</li>
    <li>pears</li>
  </ul>
</html>
And when a browser visits http://localhost:8080/meat, your app should respond with this HTML:
<html>
  <ul>
    <li>chicken</li>
    <li>beef</li>
    <li>lamb</li>
  </ul>
</html>
Try running your finished app, and visit the above URLs in your browser!
grocery.go
package main

import (
    "html/template"
    "log"
    "net/http"
)

func check(err error) {
    if err != nil {
        log.Fatal(err)
    }
}

func writeList(writer http.ResponseWriter, list []string) {
    // YOUR CODE HERE: Use the template library to parse the contents
    // of the "list.html" file. You'll get a template value and an
    // error value.
    // Pass the error value to the "check" function.
    // Now call the "Execute" method on the template. It should write
    // its output to the "writer" parameter, and it should use the
    // "list" parameter as its data value.
    // You'll get another error value back from "Execute", which
    // should be passed to "check".
}

func fruitHandler(writer http.ResponseWriter, request *http.Request) {
    writeList(writer, []string{"apples", "oranges", "pears"})
}

func meatHandler(writer http.ResponseWriter, request *http.Request) {
    writeList(writer, []string{"chicken", "beef", "lamb"})
}

func main() {
    http.HandleFunc("/fruit", fruitHandler)
    http.HandleFunc("/meat", meatHandler)
    err := http.ListenAndServe("localhost:8080", nil)
    log.Fatal(err)
}
list.html
<html>
  <ul>
    <!-- YOUR CODE HERE:
         The data value passed to the template should be a slice.
         Loop over each element in the slice, and include them in
         the output, enclosed in <li></li> tags. -->
  </ul>
</html>

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Network Protocols
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY