MCPcopy Index your code
hub / github.com/derekbanas/Go-Tutorial / createHandler

Function createHandler

webapp/webapp.go:108–126  ·  view source on GitHub ↗
(writer http.ResponseWriter,
	request *http.Request)

Source from the content-addressed store, hash-verified

106}
107
108func 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
128func main() {
129 // Our app is available at directory

Callers

nothing calls this directly

Calls 1

errorCheckFunction · 0.85

Tested by

no test coverage detected