1 Star 0 Fork 0

aping / gohttp

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
controller.go 1.21 KB
Copy Edit Raw Blame History
go-jar authored 2021-01-03 19:18 +08:00 . update
package controller
import (
"net/http"
"github.com/goinbox/gomisc"
)
type ActionContext interface {
Request() *http.Request
ResponseWriter() http.ResponseWriter
ResponseBody() []byte
SetResponseBody(body []byte)
AppendResponseBody(body []byte)
BeforeAction()
AfterAction()
Destruct()
}
type BaseContext struct {
request *http.Request
responseWriter http.ResponseWriter
responseBody []byte
}
func NewBaseContext(req *http.Request, w http.ResponseWriter) *BaseContext {
return &BaseContext{
request: req,
responseWriter: w,
}
}
func (bc *BaseContext) Request() *http.Request {
return bc.request
}
func (bc *BaseContext) ResponseWriter() http.ResponseWriter {
return bc.responseWriter
}
func (bc *BaseContext) ResponseBody() []byte {
return bc.responseBody
}
func (bc *BaseContext) SetResponseBody(body []byte) {
bc.responseBody = body
}
func (bc *BaseContext) AppendResponseBody(body []byte) {
bc.responseBody = gomisc.AppendBytes(bc.responseBody, body)
}
func (bc *BaseContext) BeforeAction() {
}
func (bc *BaseContext) AfterAction() {
}
func (bc *BaseContext) Destruct() {
}
type Controller interface {
NewActionContext(req *http.Request, w http.ResponseWriter) ActionContext
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/aping-dev/gohttp.git
git@gitee.com:aping-dev/gohttp.git
aping-dev
gohttp
gohttp
v1.1.0

Search