summaryrefslogtreecommitdiff
path: root/handler.go
blob: 16640aecffb5ce78822da82a661ae6aec403329c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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)
}