feat: add adapter

This commit is contained in:
weloe
2023-05-04 22:15:55 +08:00
parent 915624b205
commit a5652cd390
8 changed files with 455 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package go_http_context
import (
"github.com/weloe/token-go/ctx"
"net/http"
"reflect"
)
@@ -13,6 +14,14 @@ type HttpContext struct {
reqStorage ctx.ReqStorage
}
func NewHttpContext(req *http.Request, writer http.ResponseWriter) *HttpContext {
return &HttpContext{
req: NewHttpRequest(req),
response: NewResponse(req, writer),
reqStorage: NewReqStorage(req),
}
}
func (h *HttpContext) IsValidContext() bool {
return h.req != nil && !reflect.DeepEqual(h.req, &HttpRequest{})
}