go-koa requires Golang v1.11.0 or higher for go.mod support.
import "github.com/EvanLiu2968/go-koa"
package main
import "github.com/EvanLiu2968/go-koa"
func main() {
app := koa.New()
// response
app.Use(func(ctx koa.Context){
ctx.SetBody("hello, koa")
})
app.Listen(3000)
}
主要方法都集中在ctx
type Context interface {
SetBody(body string)
// 获取响应头
GetContentType()
// 设置响应头
SetContentType(cType string)
// 获取header
GetHeader(name string)
// 设置header
SetHeader(name string, value string)
// 获取cookie
GetCookie(name string)
// 设置cookie
SetCookie(name string, value string)
// ...
}
MIT