Created
May 17, 2012 18:53
-
-
Save ninnemana/2720883 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hello | |
import ( | |
"html/template" | |
"net/http" | |
"fmt" | |
) | |
func init() { | |
http.HandleFunc("/", hello) | |
http.HandleFunc("/add_person", add_person) | |
} | |
type Employee struct{ | |
First string | |
Last string | |
} | |
func hello(w http.ResponseWriter, r *http.Request){ | |
person := &Employee{First:"Alex",Last:"Ninneman"} | |
displayTemplate("new_person", "new_person.html", w, person) | |
} | |
func add_person(w http.ResponseWriter, r *http.Request){ | |
first := r.FormValue("first") | |
fmt.Println("Hello " + first + " " + r.FormValue("last")) | |
} | |
func displayTemplate(name string, filename string, w http.ResponseWriter, x interface{}){ | |
t, err := template.New(name).ParseFiles(filename) | |
err = t.ExecuteTemplate(w, filename, x) | |
if err != nil { | |
fmt.Println(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment