From cb5f3037bb18403433c2cfd0271f6bea76906aca Mon Sep 17 00:00:00 2001 From: Horus_Arch Date: Wed, 18 Feb 2015 17:03:41 +0100 Subject: Reimplementation with gorilla toolkit. --- handler.go | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 handler.go (limited to 'handler.go') diff --git a/handler.go b/handler.go new file mode 100644 index 0000000..16640ae --- /dev/null +++ b/handler.go @@ -0,0 +1,63 @@ +package main + +import ( + "fmt" + "html/template" + "log" + "net/http" +) + +func IndexHandler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Hello World! \n") + // w.Write() +} + +func RegisterHandler(w http.ResponseWriter, r *http.Request) { + log.Println("Processing registration!") + fmt.Fprintf(w, "Processing registration! \n") + // w.Write() +} + +func PrintRegisterHandler(w http.ResponseWriter, r *http.Request) { + + fmt.Fprintf(w, "Printing register etc! \n") + // w.Write() +} + +func PrintNewJobHandler(w http.ResponseWriter, r *http.Request) { + log.Printf("Printing job") + //t := template.Must(template.ParseFiles("templates/header.html", "templates/navbar.html", "templates/jobs.html", "templates/footer.html")) + t := template.Must(template.ParseFiles("templates/jobs.html", "templates/header.html", "templates/navbar.html", "templates/footer.html")) + //t := template.New("job") + //t := templ + //fmt.Printf("%s", t) + //t, err := template.ParseFiles("templates/jobs.html", "templates/header.html") + //t, err := template.ParseFiles("templates/jobs.html") + //t, err := t.ParseFiles("templates/jobs.html") + //if err != nil { + // log.Panic(err) + //} + err := t.Execute(w, nil) + if err != nil { + log.Panic(err) + } +} + +func AddNewJobHandler(w http.ResponseWriter, r *http.Request) { + log.Printf("Add new job") + + err := r.ParseForm() + if err != nil { + log.Panic(err) + } + + host := &Host{} + err = decoder.Decode(host, r.PostForm) + if err != nil { + log.Panic(err) + } + + log.Printf("%v", host) + fmt.Fprintf(w, "%s", host.Url) + Db.Debug().Save(host) +} -- cgit v1.2.3