about summary refs log tree commit diff
path: root/mooh.go
blob: 465caf51ad11974864f033bec56a1dbb1ae47402 (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
package mooh

import (
	"fmt"
	"net/http"
)

func (self *Dispatcher) ServeHTTP(resp http.ResponseWriter, req *http.Request) {

	match, err := self.Match(req)

	if err != nil {
		fmt.Printf("oups")
		return
	}

	if match == nil {
		fmt.Fprint(resp, "Not Found")
		return
	}

	request := Request{
		match.Mapping,
		req,
	}

	nresp, error := match.Route.Execute(&request)

	if error == nil {
		fmt.Fprint(resp, nresp.Content)
	} else {
		fmt.Println(error)
	}
}