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

The Delete function

The Delete method renders the Home template after deleting the customer that's found by the GetCustomerById method. The View method renders the View template after finding the customer by invoking the GetCustomerById method:

// Delete - execute Template
func Delete(writer http.ResponseWriter, request *http.Request) {
var customerId int
var customerIdStr string
customerIdStr = request.FormValue("id")
fmt.Sscanf(customerIdStr, "%d", &customerId)
var customer Customer
customer = GetCustomerById(customerId)
DeleteCustomer(customer)
var customers []Customer
customers = GetCustomers()
template_html.ExecuteTemplate(writer,"Home",customers)

}
// View - execute Template
func View(writer http.ResponseWriter, request *http.Request) {
var customerId int
var customerIdStr string
customerIdStr = request.FormValue("id")
fmt.Sscanf(customerIdStr, "%d", &customerId)
var customer Customer
customer = GetCustomerById(customerId)
fmt.Println(customer)
var customers []Customer
customers= []Customer{customer}
customers.append(customer)
template_html.ExecuteTemplate(writer,"View",customers)

}