(writer http.ResponseWriter, request *http.Request)
| 49 | } |
| 50 | |
| 51 | func interactHandler(writer http.ResponseWriter, |
| 52 | request *http.Request) { |
| 53 | |
| 54 | // Get our text from the file |
| 55 | todoVals := getStrings("todos.txt") |
| 56 | |
| 57 | // Print to the terminal |
| 58 | fmt.Printf("%#v\n", todoVals) |
| 59 | // Create a template using the html |
| 60 | tmpl, err := template.ParseFiles("view.html") |
| 61 | errorCheck(err) |
| 62 | |
| 63 | // Create a todo list with the number |
| 64 | todos := ToDoList{ |
| 65 | ToDoCount: len(todoVals), |
| 66 | ToDos: todoVals, |
| 67 | } |
| 68 | |
| 69 | // Write the template to the ResponseWriter |
| 70 | // Pass the todo struct data |
| 71 | err = tmpl.Execute(writer, todos) |
| 72 | } |
| 73 | |
| 74 | // Retreives lines of text from a file |
| 75 | func getStrings(fileName string) []string { |
nothing calls this directly
no test coverage detected