Writing a Simple Web Application
Explore building a simple web application using Go by setting up routes for different URL endpoints, handling GET and POST requests, and serving HTML content through a web server. This lesson guides you through creating a web form, processing input, and safely handling content types for browser display.
We'll cover the following...
A web application
In the following program from line 7 to line 10, we see how the HTML, needed for our web form (which is a simple input form with text box and submit button) is stored in a multi-line string constant form.
The program starts a webserver on port 3000 at line 39. It uses a combined if statement so that, whenever an error occurs, the web server stops with a panic statement (see line 40). Before starting a webserver, we see two so-called routing statements:
http.HandleFunc("/test1", SimpleServer)at line 37