-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.go
55 lines (44 loc) · 983 Bytes
/
application.go
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
package alpha
import (
"log"
"net/http"
)
type Address struct {
Port string
Hostname string
}
type HashObject map[string]interface{}
type Alpha struct {
Request *Request
Response *Response
Settings HashObject
}
func (a *Alpha) init() {
a.Settings = HashObject{}
}
func (a *Alpha) handle() http.HandlerFunc {
req := a.Request
res := a.Response
return func (w http.ResponseWriter, r *http.Request) {
req.In = r
res.Out = w
req.Res = res
res.Req = req
req.Query = r.URL.Query()
req.Headers = r.Header
res.Headers = w.Header()
// test
res.Charset = "UTF-8"
res.Type("html")
res.SetHeader("X-Powered-By", "Alpha")
res.Send("Hello " + req.Get("User-Agent") + " " + req.Path());
}
}
func (a *Alpha) Listen(address Address) *http.Server {
server := &http.Server{
Addr: address.Hostname + ":" + address.Port,
Handler: a.handle(),
}
log.Fatal(server.ListenAndServe())
return server
}