Learn Data Structures and Algorithms with Golang
上QQ阅读APP看书,第一时间看更新

The Insert function

The Insert function invokes the GetCustomers method to get an array of customers and renders the Home template with the writer and customers arrays as parameters by invoking the ExecuteTemplate method. This is shown in the following code:

// Insert - execute template
func Insert(writer http.ResponseWriter, request *http.Request) {

var customer Customer
customer.CustomerName = request.FormValue("customername")
customer.SSN = request.FormValue("ssn")
InsertCustomer(customer)
var customers []Customer
customers = GetCustomers()
template_html.ExecuteTemplate(writer,"Home",customers)

}