aboutsummaryrefslogtreecommitdiff
path: root/cmd/http/handle.go
blob: a8b1da11a1c7b2545bae45282250c94c5674d3d4 (plain) (blame)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main

import (
	"net/http"
	"strings"
)

func (app *application) home(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html; charset=utf-8")

	path := strings.Split(r.URL.Path, "/")
	if path[1] != "" {
		app.notFound(w)
	} else {
		/* 		p, err := app.aggregate("html/projects")
		   		if err != nil {
		   			app.serverError(w, err)
		   		} */

		err := renderTemplate(w, "index", nil)
		if err != nil {
			app.serverError(w, err)
		}
	}
}

func (app *application) faq(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html; charset=utf-8")

	path := strings.Split(r.URL.Path, "/")
	if path[1] != "faq" {
		app.notFound(w)
	} else {
		err := renderTemplate(w, "faq", nil)
		if err != nil {
			app.serverError(w, err)
		}
	}
}

func (app *application) about(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html; charset=utf-8")

	path := strings.Split(r.URL.Path, "/")
	if path[1] != "about" {
		app.notFound(w)
	} else {
		err := renderTemplate(w, "about", nil)
		if err != nil {
			app.serverError(w, err)
		}
	}
}

func (app *application) gallery(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html; charset=utf-8")

	path := strings.Split(r.URL.Path, "/")
	if path[1] != "gallery" {
		app.notFound(w)
	} else {
		err := renderTemplate(w, "gallery", nil)
		if err != nil {
			app.serverError(w, err)
		}
	}
}

func (app *application) blog(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html; charset=utf-8")

	path := strings.Split(r.URL.Path, "/")
	if path[1] != "blog" {
		app.notFound(w)
	} else {
		err := renderTemplate(w, "blog", nil)
		if err != nil {
			app.serverError(w, err)
		}
	}
	/*
		 	if len(path) > 4 {
				app.notFound(w)
			} else if len(path) == 4 && path[3] == "" {
				http.Redirect(w, r, "/"+path[1]+"/"+path[2], http.StatusFound)
			} else {
				post, err := app.readFile("html" + strings.TrimSuffix(r.URL.Path, "/") + ".tmpl.html")
				if err != nil {
					app.notFound(w)
					return
				}

				var posts []*Post
				posts = append(posts, post)
				p := &Posts{Contents: posts}

				err = renderTemplate(w, path[1]+"/"+path[2], p)
				if err != nil {
					app.serverError(w, err)
				}
			}
	*/
}