-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpserver_test.go
More file actions
37 lines (31 loc) · 1.25 KB
/
httpserver_test.go
File metadata and controls
37 lines (31 loc) · 1.25 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
package httpserver
import (
"io"
"net/http"
"strings"
"testing"
)
func HandleIndex(w http.ResponseWriter, r *http.Request, param CUrlParam, server CHttpServer, userdata interface{}) bool {
io.WriteString(w, "index")
return true
}
func HandleIndex2(w http.ResponseWriter, r *http.Request, param CUrlParam, server CHttpServer, userdata interface{}) bool {
io.WriteString(w, "index2")
return true
}
func HandleHello(w http.ResponseWriter, r *http.Request, param CUrlParam, server CHttpServer, userdata interface{}) bool {
io.WriteString(w, strings.Join([]string{"hello", *param.ByName("name")}, ":"))
return true
}
func HandleHello2(w http.ResponseWriter, r *http.Request, param CUrlParam, server CHttpServer, userdata interface{}) bool {
io.WriteString(w, strings.Join([]string{"hello", *param.ByName("name"), "age", *param.ByName("age")}, ":"))
return true
}
func TestHttpServer(t *testing.T) {
server := NewHttpServer()
server.Subscribe("/", GET, NewRouterHandler(nil, HandleIndex))
server.Subscribe("/index", GET, NewRouterHandler(nil, HandleIndex2))
server.Subscribe("/hello/:name", GET, NewRouterHandler(nil, HandleHello))
server.Subscribe("/hello/name/:name/age/:age", GET, NewRouterHandler(nil, HandleHello2))
http.ListenAndServe(":59000", server)
}