mirror of
https://github.com/eolinker/apinto
synced 2025-10-05 08:47:04 +08:00
合并context
This commit is contained in:
@@ -21,37 +21,19 @@ type Context struct {
|
||||
proxyRequests []http_service.IRequest
|
||||
requestID string
|
||||
response *Response
|
||||
responseError error
|
||||
requestReader *RequestReader
|
||||
ctx context.Context
|
||||
|
||||
requestReader *RequestReader
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func (ctx *Context) Proxies() []http_service.IRequest {
|
||||
return ctx.proxyRequests
|
||||
}
|
||||
|
||||
//func (ctx *Context) SetField(key, value string) {
|
||||
// if ctx.entry == nil {
|
||||
// ctx.entry = NewEntry()
|
||||
// }
|
||||
// ctx.entry.SetField(key, value)
|
||||
//}
|
||||
//
|
||||
//func (ctx *Context) SetChildren(name string, fields []map[string]string) {
|
||||
// if ctx.entry == nil {
|
||||
// ctx.entry = NewEntry()
|
||||
// }
|
||||
// ctx.entry.SetChildren(name, fields)
|
||||
//}
|
||||
|
||||
func (ctx *Context) Response() http_service.IResponse {
|
||||
return ctx.response
|
||||
}
|
||||
|
||||
func (ctx *Context) ResponseError() error {
|
||||
return ctx.responseError
|
||||
}
|
||||
|
||||
type Finish interface {
|
||||
Finish() error
|
||||
}
|
||||
@@ -62,9 +44,9 @@ func (ctx *Context) SendTo(address string, timeout time.Duration) error {
|
||||
ctx.proxyRequests = append(ctx.proxyRequests, clone)
|
||||
request := ctx.proxyRequest.Request()
|
||||
|
||||
ctx.responseError = fasthttp_client.ProxyTimeout(address, request, &ctx.fastHttpRequestCtx.Response, timeout)
|
||||
ctx.response.responseError = fasthttp_client.ProxyTimeout(address, request, &ctx.fastHttpRequestCtx.Response, timeout)
|
||||
|
||||
return ctx.responseError
|
||||
return ctx.response.responseError
|
||||
|
||||
}
|
||||
|
||||
@@ -104,7 +86,6 @@ func NewContext(ctx *fasthttp.RequestCtx) *Context {
|
||||
proxyRequest: NewProxyRequest(&ctx.Request, ctx.RemoteIP().String()),
|
||||
proxyRequests: make([]http_service.IRequest, 0, 5),
|
||||
response: NewResponse(ctx),
|
||||
responseError: nil,
|
||||
}
|
||||
|
||||
return newCtx
|
||||
@@ -117,9 +98,9 @@ func (ctx *Context) RequestId() string {
|
||||
|
||||
//Finish finish
|
||||
func (ctx *Context) Finish() {
|
||||
if ctx.responseError != nil {
|
||||
if ctx.response.responseError != nil {
|
||||
ctx.fastHttpRequestCtx.SetStatusCode(504)
|
||||
ctx.fastHttpRequestCtx.SetBodyString(ctx.responseError.Error())
|
||||
ctx.fastHttpRequestCtx.SetBodyString(ctx.response.responseError.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user