-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrest.go
More file actions
73 lines (56 loc) · 1.64 KB
/
rest.go
File metadata and controls
73 lines (56 loc) · 1.64 KB
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
// Copyright 2018 Portal Direc's authors. All rights reserved.
//
// Authors: Rafael Campos Nunes <rafaelnunes@alunos.utfpr.edu.br>
// ... <email>
//
// Use of this source code is governed by a Apache License. The license can be
// found (LICENSE) at the root of the project.
// DOCUMENTATION
// ---------------------------------------------------------------------------
// This file concerns the definition of requests used by the server as
// also the render to the client.
package main
import (
"html/template"
"log"
"net/http"
)
func handlePage(title string, w http.ResponseWriter, r *http.Request) {
page, err := Load(title)
if err == nil {
render(w, Filepath(title), page)
} else {
if debug {
log.Printf("The page \"%s\" couldn't be loaded. Reason: %v",
Filepath(title), err)
}
}
}
func render(w http.ResponseWriter, tmpl string, p *Page) {
t, err := template.ParseFiles(tmpl)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
err = t.Execute(w, p)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
func HandleRoot(w http.ResponseWriter, r *http.Request) {
handlePage("index", w, r)
}
func HandleDepex(w http.ResponseWriter, r *http.Request) {
handlePage("depex", w, r)
}
func HandleDepec(w http.ResponseWriter, r *http.Request) {
handlePage("depec", w, r)
}
func HandleDepet(w http.ResponseWriter, r *http.Request) {
handlePage("depet", w, r)
}
func HandleOportunities(w http.ResponseWriter, r *http.Request) {
handlePage("oportunities", w, r)
}
func HandleNotFound(w http.ResponseWriter, r *http.Request) {
handlePage("404", w, r)
}