(writer http.ResponseWriter, request *http.Request)
| 106 | } |
| 107 | |
| 108 | func createHandler(writer http.ResponseWriter, |
| 109 | request *http.Request) { |
| 110 | todo := request.FormValue("todo") |
| 111 | // Define options for working with the file |
| 112 | options := os.O_WRONLY | os.O_APPEND | os.O_CREATE |
| 113 | // Open file with options and permissions |
| 114 | file, err := os.OpenFile("todos.txt", options, os.FileMode(0600)) |
| 115 | errorCheck(err) |
| 116 | // Append new text to file |
| 117 | _, err = fmt.Fprintln(file, todo) |
| 118 | errorCheck(err) |
| 119 | // Close file |
| 120 | err = file.Close() |
| 121 | errorCheck(err) |
| 122 | // Redirect to defined page while passing |
| 123 | // ResponseWriter, original request, |
| 124 | // and a successful request message |
| 125 | http.Redirect(writer, request, "/interact", http.StatusFound) |
| 126 | } |
| 127 | |
| 128 | func main() { |
| 129 | // Our app is available at directory |
nothing calls this directly
no test coverage detected