-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (32 loc) · 776 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
package main
import (
"log"
"github.com/buaazp/fasthttprouter"
"github.com/valyala/fasthttp"
)
func Equal(ctx *fasthttp.RequestCtx) {
_, _ = ctx.WriteString(`Hello World`)
}
func Contains(ctx *fasthttp.RequestCtx) {
_, _ = ctx.WriteString(`24sdfq23rwasdfasdfHelloadfasdf23sadfasdfef2`)
}
func Pattern(ctx *fasthttp.RequestCtx) {
_, _ = ctx.WriteString(`{"code": 200, "msg": "ok", "data":{}}`)
}
func loadRouter() *fasthttprouter.Router {
r := fasthttprouter.New()
r.GET("/equal", Equal)
r.POST("/contains", Contains)
r.GET("/pattern", Pattern)
return r
}
func main() {
r := loadRouter()
server := fasthttp.Server{
Handler: r.Handler,
}
err := server.ListenAndServe(":8080")
if err != nil {
log.Fatalf("server start error:%s\n", err.Error())
}
}