-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.go
45 lines (37 loc) · 932 Bytes
/
main.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
package main
import (
"github.com/anonymous5l/console"
"github.com/valyala/fasthttp"
"ibreaker/aweme"
"strings"
)
var router map[string]map[string]fasthttp.RequestHandler
func requestHandler(ctx *fasthttp.RequestCtx) {
path := string(ctx.RequestURI())
paths := strings.Split(path, "/")[1:]
if len(paths) < 2 {
ctx.Response.SetStatusCode(400)
return
}
// main
console.Log("Request: %#v", paths)
if first, ok := router[paths[0]]; !ok {
ctx.Response.SetStatusCode(404)
return
} else if first == nil {
ctx.Response.SetStatusCode(500)
return
} else if second, ok := first[paths[1]]; !ok {
ctx.Response.SetStatusCode(404)
return
} else {
second(ctx)
}
}
func main() {
router = make(map[string]map[string]fasthttp.RequestHandler)
router["aweme"] = aweme.InitAwemeRouter()
if err := fasthttp.ListenAndServe("127.0.0.1:25583", requestHandler); err != nil {
console.Err("fasthttp: %s", err)
}
}