mirror of
https://github.com/labstack/echo.git
synced 2025-03-21 21:27:04 +02:00
parent
00bf0d651f
commit
b10c93cd17
22
context.go
22
context.go
@ -26,8 +26,8 @@ type (
|
||||
// response objects, path parameters, data and registered handler.
|
||||
Context interface {
|
||||
netContext.Context
|
||||
SetNetContext(netContext.Context)
|
||||
NetContext() netContext.Context
|
||||
SetNetContext(netContext.Context)
|
||||
Request() engine.Request
|
||||
Response() engine.Response
|
||||
Path() string
|
||||
@ -36,8 +36,8 @@ type (
|
||||
ParamNames() []string
|
||||
Query(string) string
|
||||
Form(string) string
|
||||
Set(string, interface{})
|
||||
Get(string) interface{}
|
||||
Set(string, interface{})
|
||||
Bind(interface{}) error
|
||||
Render(int, string, interface{}) error
|
||||
HTML(int, string) error
|
||||
@ -90,14 +90,14 @@ func NewContext(req engine.Request, res engine.Response, e *Echo) Context {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *context) SetNetContext(ctx netContext.Context) {
|
||||
c.netContext = ctx
|
||||
}
|
||||
|
||||
func (c *context) NetContext() netContext.Context {
|
||||
return c.netContext
|
||||
}
|
||||
|
||||
func (c *context) SetNetContext(ctx netContext.Context) {
|
||||
c.netContext = ctx
|
||||
}
|
||||
|
||||
func (c *context) Deadline() (deadline time.Time, ok bool) {
|
||||
return c.netContext.Deadline()
|
||||
}
|
||||
@ -169,11 +169,6 @@ func (c *context) Form(name string) string {
|
||||
return c.request.FormValue(name)
|
||||
}
|
||||
|
||||
// Get retrieves data from the context.
|
||||
func (c *context) Get(key string) interface{} {
|
||||
return c.store[key]
|
||||
}
|
||||
|
||||
// Set saves data in the context.
|
||||
func (c *context) Set(key string, val interface{}) {
|
||||
if c.store == nil {
|
||||
@ -182,6 +177,11 @@ func (c *context) Set(key string, val interface{}) {
|
||||
c.store[key] = val
|
||||
}
|
||||
|
||||
// Get retrieves data from the context.
|
||||
func (c *context) Get(key string) interface{} {
|
||||
return c.store[key]
|
||||
}
|
||||
|
||||
// Bind binds the request body into specified type `i`. The default binder does
|
||||
// it based on Content-Type header.
|
||||
func (c *context) Bind(i interface{}) error {
|
||||
|
@ -9,16 +9,18 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
// Engine defines an interface for HTTP server.
|
||||
// Engine defines the interface for HTTP server.
|
||||
Engine interface {
|
||||
SetHandler(Handler)
|
||||
SetLogger(*log.Logger)
|
||||
Start()
|
||||
}
|
||||
|
||||
// Request defines an interface for HTTP request.
|
||||
// Request defines the interface for HTTP request.
|
||||
Request interface {
|
||||
// TLS returns true if connection is TLS otherwise false.
|
||||
TLS() bool
|
||||
|
||||
Scheme() string
|
||||
Host() string
|
||||
URI() string
|
||||
@ -27,6 +29,7 @@ type (
|
||||
// Proto() string
|
||||
// ProtoMajor() int
|
||||
// ProtoMinor() int
|
||||
UserAgent() string
|
||||
RemoteAddress() string
|
||||
Method() string
|
||||
Body() io.ReadCloser
|
||||
@ -35,7 +38,7 @@ type (
|
||||
MultipartForm() (*multipart.Form, error)
|
||||
}
|
||||
|
||||
// Response defines an interface for HTTP response.
|
||||
// Response defines the interface for HTTP response.
|
||||
Response interface {
|
||||
Header() Header
|
||||
WriteHeader(int)
|
||||
@ -43,22 +46,22 @@ type (
|
||||
Status() int
|
||||
Size() int64
|
||||
Committed() bool
|
||||
SetWriter(io.Writer)
|
||||
Writer() io.Writer
|
||||
SetWriter(io.Writer)
|
||||
}
|
||||
|
||||
// Header defines an interface for HTTP header.
|
||||
// Header defines the interface for HTTP header.
|
||||
Header interface {
|
||||
Add(string, string)
|
||||
Del(string)
|
||||
Get(string) string
|
||||
Set(string, string)
|
||||
Get(string) string
|
||||
}
|
||||
|
||||
// URL defines an interface for HTTP request url.
|
||||
// URL defines the interface for HTTP request url.
|
||||
URL interface {
|
||||
SetPath(string)
|
||||
Path() string
|
||||
SetPath(string)
|
||||
QueryValue(string) string
|
||||
}
|
||||
|
||||
|
@ -5,47 +5,57 @@ package fasthttp
|
||||
import "github.com/valyala/fasthttp"
|
||||
|
||||
type (
|
||||
// RequestHeader holds `fasthttp.RequestHeader`.
|
||||
RequestHeader struct {
|
||||
*fasthttp.RequestHeader
|
||||
}
|
||||
|
||||
// ResponseHeader holds `fasthttp.ResponseHeader`.
|
||||
ResponseHeader struct {
|
||||
*fasthttp.ResponseHeader
|
||||
}
|
||||
)
|
||||
|
||||
// Add implements `Header#Add` method.
|
||||
func (h *RequestHeader) Add(key, val string) {
|
||||
// h.RequestHeader.Add(key, val)
|
||||
}
|
||||
|
||||
// Del implements `Header#Del` method.
|
||||
func (h *RequestHeader) Del(key string) {
|
||||
h.RequestHeader.Del(key)
|
||||
}
|
||||
|
||||
func (h *RequestHeader) Get(key string) string {
|
||||
return string(h.Peek(key))
|
||||
}
|
||||
|
||||
// Set implements `Header#Set` method.
|
||||
func (h *RequestHeader) Set(key, val string) {
|
||||
h.RequestHeader.Set(key, val)
|
||||
}
|
||||
|
||||
// Get implements `Header#Get` method.
|
||||
func (h *RequestHeader) Get(key string) string {
|
||||
return string(h.Peek(key))
|
||||
}
|
||||
|
||||
func (h *RequestHeader) reset(hdr *fasthttp.RequestHeader) {
|
||||
h.RequestHeader = hdr
|
||||
}
|
||||
|
||||
// Add implements `Header#Add` method.
|
||||
func (h *ResponseHeader) Add(key, val string) {
|
||||
// h.header.Add(key, val)
|
||||
}
|
||||
|
||||
// Del implements `Header#Del` method.
|
||||
func (h *ResponseHeader) Del(key string) {
|
||||
h.ResponseHeader.Del(key)
|
||||
}
|
||||
|
||||
// Get implements `Header#Get` method.
|
||||
func (h *ResponseHeader) Get(key string) string {
|
||||
return string(h.Peek(key))
|
||||
}
|
||||
|
||||
// Set implements `Header#Set` method.
|
||||
func (h *ResponseHeader) Set(key, val string) {
|
||||
h.ResponseHeader.Set(key, val)
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
// Request implements `engine.Request`.
|
||||
Request struct {
|
||||
*fasthttp.RequestCtx
|
||||
url engine.URL
|
||||
@ -22,58 +23,67 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func NewRequest(c *fasthttp.RequestCtx) *Request {
|
||||
return &Request{
|
||||
RequestCtx: c,
|
||||
url: &URL{URI: c.URI()},
|
||||
header: &RequestHeader{&c.Request.Header},
|
||||
}
|
||||
}
|
||||
|
||||
// TLS implements `Request#TLS` method.
|
||||
func (r *Request) TLS() bool {
|
||||
return r.IsTLS()
|
||||
}
|
||||
|
||||
// Scheme implements `Request#Scheme` method.
|
||||
func (r *Request) Scheme() string {
|
||||
return string(r.RequestCtx.URI().Scheme())
|
||||
}
|
||||
|
||||
// Host implements `Request#Host` method.
|
||||
func (r *Request) Host() string {
|
||||
return string(r.RequestCtx.Host())
|
||||
}
|
||||
|
||||
func (r *Request) URI() string {
|
||||
return string(r.RequestURI())
|
||||
}
|
||||
|
||||
// URL implements `Request#URL` method.
|
||||
func (r *Request) URL() engine.URL {
|
||||
return r.url
|
||||
}
|
||||
|
||||
// Header implements `Request#Header` method.
|
||||
func (r *Request) Header() engine.Header {
|
||||
return r.header
|
||||
}
|
||||
|
||||
// UserAgent implements `Request#UserAgent` method.
|
||||
func (r *Request) UserAgent() string {
|
||||
return string(r.RequestCtx.UserAgent())
|
||||
}
|
||||
|
||||
// RemoteAddress implements `Request#RemoteAddress` method.
|
||||
func (r *Request) RemoteAddress() string {
|
||||
return r.RemoteAddr().String()
|
||||
}
|
||||
|
||||
// Method implements `Request#Method` method.
|
||||
func (r *Request) Method() string {
|
||||
return string(r.RequestCtx.Method())
|
||||
}
|
||||
|
||||
// URI implements `Request#URI` method.
|
||||
func (r *Request) URI() string {
|
||||
return string(r.RequestURI())
|
||||
}
|
||||
|
||||
// Body implements `Request#Body` method.
|
||||
func (r *Request) Body() io.ReadCloser {
|
||||
return ioutil.NopCloser(bytes.NewBuffer(r.PostBody()))
|
||||
}
|
||||
|
||||
// FormValue implements `Request#FormValue` method.
|
||||
func (r *Request) FormValue(name string) string {
|
||||
return string(r.RequestCtx.FormValue(name))
|
||||
}
|
||||
|
||||
// FormFile implements `Request#FormFile` method.
|
||||
func (r *Request) FormFile(name string) (*multipart.FileHeader, error) {
|
||||
return r.RequestCtx.FormFile(name)
|
||||
}
|
||||
|
||||
// MultipartForm implements `Request#MultipartForm` method.
|
||||
func (r *Request) MultipartForm() (*multipart.Form, error) {
|
||||
return r.RequestCtx.MultipartForm()
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
// Response implements `engine.Response`.
|
||||
Response struct {
|
||||
*fasthttp.RequestCtx
|
||||
header engine.Header
|
||||
@ -23,19 +24,12 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func NewResponse(c *fasthttp.RequestCtx) *Response {
|
||||
return &Response{
|
||||
RequestCtx: c,
|
||||
header: &ResponseHeader{&c.Response.Header},
|
||||
writer: c,
|
||||
logger: log.New("test"),
|
||||
}
|
||||
}
|
||||
|
||||
// Header implements `Response#Header` method.
|
||||
func (r *Response) Header() engine.Header {
|
||||
return r.header
|
||||
}
|
||||
|
||||
// WriteHeader implements `Response#WriteHeader` method.
|
||||
func (r *Response) WriteHeader(code int) {
|
||||
if r.committed {
|
||||
r.logger.Warn("response already committed")
|
||||
@ -46,30 +40,36 @@ func (r *Response) WriteHeader(code int) {
|
||||
r.committed = true
|
||||
}
|
||||
|
||||
// Write implements `Response#Write` method.
|
||||
func (r *Response) Write(b []byte) (int, error) {
|
||||
return r.RequestCtx.Write(b)
|
||||
}
|
||||
|
||||
// Status implements `Response#Status` method.
|
||||
func (r *Response) Status() int {
|
||||
return r.status
|
||||
}
|
||||
|
||||
// Size implements `Response#Size` method.
|
||||
func (r *Response) Size() int64 {
|
||||
return r.size
|
||||
}
|
||||
|
||||
// Committed implements `Response#Committed` method.
|
||||
func (r *Response) Committed() bool {
|
||||
return r.committed
|
||||
}
|
||||
|
||||
func (r *Response) SetWriter(w io.Writer) {
|
||||
r.writer = w
|
||||
}
|
||||
|
||||
// Writer implements `Response#Writer` method.
|
||||
func (r *Response) Writer() io.Writer {
|
||||
return r.writer
|
||||
}
|
||||
|
||||
// SetWriter implements `Response#SetWriter` method.
|
||||
func (r *Response) SetWriter(w io.Writer) {
|
||||
r.writer = w
|
||||
}
|
||||
|
||||
func (r *Response) reset(c *fasthttp.RequestCtx, h engine.Header) {
|
||||
r.RequestCtx = c
|
||||
r.header = h
|
||||
|
@ -12,14 +12,15 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
// Server implements `engine.Engine`.
|
||||
Server struct {
|
||||
config engine.Config
|
||||
handler engine.Handler
|
||||
logger *log.Logger
|
||||
pool *Pool
|
||||
pool *pool
|
||||
}
|
||||
|
||||
Pool struct {
|
||||
pool struct {
|
||||
request sync.Pool
|
||||
response sync.Pool
|
||||
requestHeader sync.Pool
|
||||
@ -28,11 +29,13 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
// New returns an instance of `fasthttp.Server` with specified listen address.
|
||||
func New(addr string) *Server {
|
||||
c := engine.Config{Address: addr}
|
||||
return NewFromConfig(c)
|
||||
}
|
||||
|
||||
// NewFromTLS returns an instance of `fasthttp.Server` from TLS config.
|
||||
func NewFromTLS(addr, certfile, keyfile string) *Server {
|
||||
c := engine.Config{
|
||||
Address: addr,
|
||||
@ -42,10 +45,11 @@ func NewFromTLS(addr, certfile, keyfile string) *Server {
|
||||
return NewFromConfig(c)
|
||||
}
|
||||
|
||||
// NewFromConfig returns an instance of `standard.Server` from config.
|
||||
func NewFromConfig(c engine.Config) (s *Server) {
|
||||
s = &Server{
|
||||
config: c,
|
||||
pool: &Pool{
|
||||
pool: &pool{
|
||||
request: sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &Request{}
|
||||
@ -80,14 +84,17 @@ func NewFromConfig(c engine.Config) (s *Server) {
|
||||
return
|
||||
}
|
||||
|
||||
// SetHandler implements `Engine#SetHandler` method.
|
||||
func (s *Server) SetHandler(h engine.Handler) {
|
||||
s.handler = h
|
||||
}
|
||||
|
||||
// SetLogger implements `Engine#SetLogger` method.
|
||||
func (s *Server) SetLogger(l *log.Logger) {
|
||||
s.logger = l
|
||||
}
|
||||
|
||||
// Start implements `Engine#Start` method.
|
||||
func (s *Server) Start() {
|
||||
handler := func(c *fasthttp.RequestCtx) {
|
||||
// Request
|
||||
|
@ -5,19 +5,23 @@ package fasthttp
|
||||
import "github.com/valyala/fasthttp"
|
||||
|
||||
type (
|
||||
// URL implements `engine.URL`.
|
||||
URL struct {
|
||||
*fasthttp.URI
|
||||
}
|
||||
)
|
||||
|
||||
func (u *URL) SetPath(path string) {
|
||||
// return string(u.URI.Path())
|
||||
}
|
||||
|
||||
// Path implements `URL#Path` method.
|
||||
func (u *URL) Path() string {
|
||||
return string(u.URI.Path())
|
||||
}
|
||||
|
||||
// SetPath implements `URL#SetPath` method.
|
||||
func (u *URL) SetPath(path string) {
|
||||
// return string(u.URI.Path())
|
||||
}
|
||||
|
||||
// QueryValue implements `URL#QueryValue` method.
|
||||
func (u *URL) QueryValue(name string) string {
|
||||
return ""
|
||||
}
|
||||
|
@ -3,27 +3,32 @@ package standard
|
||||
import "net/http"
|
||||
|
||||
type (
|
||||
// Header implements `engine.Header`.
|
||||
Header struct {
|
||||
http.Header
|
||||
}
|
||||
)
|
||||
|
||||
// Add implements `Header#Add` method.
|
||||
func (h *Header) Add(key, val string) {
|
||||
h.Header.Add(key, val)
|
||||
}
|
||||
|
||||
// Del implements `Header#Del` method.
|
||||
func (h *Header) Del(key string) {
|
||||
h.Header.Del(key)
|
||||
}
|
||||
|
||||
func (h *Header) Get(key string) string {
|
||||
return h.Header.Get(key)
|
||||
}
|
||||
|
||||
// Set implements `Header#Set` method.
|
||||
func (h *Header) Set(key, val string) {
|
||||
h.Header.Set(key, val)
|
||||
}
|
||||
|
||||
// Get implements `Header#Get` method.
|
||||
func (h *Header) Get(key string) string {
|
||||
return h.Header.Get(key)
|
||||
}
|
||||
|
||||
func (h *Header) reset(hdr http.Header) {
|
||||
h.Header = hdr
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
// Request implements `engine.Request`.
|
||||
Request struct {
|
||||
*http.Request
|
||||
url engine.URL
|
||||
@ -16,18 +17,12 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func NewRequest(r *http.Request) *Request {
|
||||
return &Request{
|
||||
Request: r,
|
||||
url: &URL{URL: r.URL},
|
||||
header: &Header{r.Header},
|
||||
}
|
||||
}
|
||||
|
||||
// TLS implements `Request#TLS` method.
|
||||
func (r *Request) TLS() bool {
|
||||
return r.Request.TLS != nil
|
||||
}
|
||||
|
||||
// Scheme implements `Request#Scheme` method.
|
||||
func (r *Request) Scheme() string {
|
||||
if r.TLS() {
|
||||
return "https"
|
||||
@ -35,14 +30,17 @@ func (r *Request) Scheme() string {
|
||||
return "http"
|
||||
}
|
||||
|
||||
// Host implements `Request#Host` method.
|
||||
func (r *Request) Host() string {
|
||||
return r.Request.Host
|
||||
}
|
||||
|
||||
// URL implements `Request#URL` method.
|
||||
func (r *Request) URL() engine.URL {
|
||||
return r.url
|
||||
}
|
||||
|
||||
// Header implements `Request#URL` method.
|
||||
func (r *Request) Header() engine.Header {
|
||||
return r.header
|
||||
}
|
||||
@ -59,31 +57,43 @@ func (r *Request) Header() engine.Header {
|
||||
// return r.request.ProtoMinor()
|
||||
// }
|
||||
|
||||
// UserAgent implements `Request#UserAgent` method.
|
||||
func (r *Request) UserAgent() string {
|
||||
return r.Request.UserAgent()
|
||||
}
|
||||
|
||||
// RemoteAddress implements `Request#RemoteAddress` method.
|
||||
func (r *Request) RemoteAddress() string {
|
||||
return r.RemoteAddr
|
||||
}
|
||||
|
||||
// Method implements `Request#Method` method.
|
||||
func (r *Request) Method() string {
|
||||
return r.Request.Method
|
||||
}
|
||||
|
||||
// URI implements `Request#URI` method.
|
||||
func (r *Request) URI() string {
|
||||
return r.RequestURI
|
||||
}
|
||||
|
||||
// Body implements `Request#Body` method.
|
||||
func (r *Request) Body() io.ReadCloser {
|
||||
return r.Request.Body
|
||||
}
|
||||
|
||||
// FormValue implements `Request#FormValue` method.
|
||||
func (r *Request) FormValue(name string) string {
|
||||
return r.Request.FormValue(name)
|
||||
}
|
||||
|
||||
// FormFile implements `Request#FormFile` method.
|
||||
func (r *Request) FormFile(name string) (*multipart.FileHeader, error) {
|
||||
_, fh, err := r.Request.FormFile(name)
|
||||
return fh, err
|
||||
}
|
||||
|
||||
// MultipartForm implements `Request#MultipartForm` method.
|
||||
func (r *Request) MultipartForm() (*multipart.Form, error) {
|
||||
r.Request.ParseMultipartForm(32 << 20) // 32 MB
|
||||
return r.Request.MultipartForm, nil
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
// Response implements `engine.Response`.
|
||||
Response struct {
|
||||
http.ResponseWriter
|
||||
header engine.Header
|
||||
@ -20,19 +21,12 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func NewResponse(w http.ResponseWriter, l *log.Logger) *Response {
|
||||
return &Response{
|
||||
ResponseWriter: w,
|
||||
header: &Header{w.Header()},
|
||||
writer: w,
|
||||
logger: l,
|
||||
}
|
||||
}
|
||||
|
||||
// Header implements `Response#Header` method.
|
||||
func (r *Response) Header() engine.Header {
|
||||
return r.header
|
||||
}
|
||||
|
||||
// WriteHeader implements `Response#WriteHeader` method.
|
||||
func (r *Response) WriteHeader(code int) {
|
||||
if r.committed {
|
||||
r.logger.Warn("response already committed")
|
||||
@ -43,32 +37,38 @@ func (r *Response) WriteHeader(code int) {
|
||||
r.committed = true
|
||||
}
|
||||
|
||||
// Write implements `Response#Write` method.
|
||||
func (r *Response) Write(b []byte) (n int, err error) {
|
||||
n, err = r.writer.Write(b)
|
||||
r.size += int64(n)
|
||||
return
|
||||
}
|
||||
|
||||
// Status implements `Response#Status` method.
|
||||
func (r *Response) Status() int {
|
||||
return r.status
|
||||
}
|
||||
|
||||
// Size implements `Response#Size` method.
|
||||
func (r *Response) Size() int64 {
|
||||
return r.size
|
||||
}
|
||||
|
||||
// Committed implements `Response#Committed` method.
|
||||
func (r *Response) Committed() bool {
|
||||
return r.committed
|
||||
}
|
||||
|
||||
func (r *Response) SetWriter(w io.Writer) {
|
||||
r.writer = w
|
||||
}
|
||||
|
||||
// Writer implements `Response#Writer` method.
|
||||
func (r *Response) Writer() io.Writer {
|
||||
return r.writer
|
||||
}
|
||||
|
||||
// SetWriter implements `Response#SetWriter` method.
|
||||
func (r *Response) SetWriter(w io.Writer) {
|
||||
r.writer = w
|
||||
}
|
||||
|
||||
func (r *Response) reset(w http.ResponseWriter, h engine.Header) {
|
||||
r.ResponseWriter = w
|
||||
r.header = h
|
||||
|
@ -10,15 +10,16 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
// Server implements `engine.Engine`.
|
||||
Server struct {
|
||||
*http.Server
|
||||
config engine.Config
|
||||
handler engine.Handler
|
||||
logger *log.Logger
|
||||
pool *Pool
|
||||
pool *pool
|
||||
}
|
||||
|
||||
Pool struct {
|
||||
pool struct {
|
||||
request sync.Pool
|
||||
response sync.Pool
|
||||
header sync.Pool
|
||||
@ -26,11 +27,13 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
// New returns an instance of `standard.Server` with specified listen address.
|
||||
func New(addr string) *Server {
|
||||
c := engine.Config{Address: addr}
|
||||
return NewFromConfig(c)
|
||||
}
|
||||
|
||||
// NewFromTLS returns an instance of `standard.Server` from TLS config.
|
||||
func NewFromTLS(addr, certfile, keyfile string) *Server {
|
||||
c := engine.Config{
|
||||
Address: addr,
|
||||
@ -40,11 +43,12 @@ func NewFromTLS(addr, certfile, keyfile string) *Server {
|
||||
return NewFromConfig(c)
|
||||
}
|
||||
|
||||
// NewFromConfig returns an instance of `standard.Server` from config.
|
||||
func NewFromConfig(c engine.Config) (s *Server) {
|
||||
s = &Server{
|
||||
Server: new(http.Server),
|
||||
config: c,
|
||||
pool: &Pool{
|
||||
pool: &pool{
|
||||
request: sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &Request{}
|
||||
@ -76,14 +80,17 @@ func NewFromConfig(c engine.Config) (s *Server) {
|
||||
return
|
||||
}
|
||||
|
||||
// SetHandler implements `Engine#SetHandler` method.
|
||||
func (s *Server) SetHandler(h engine.Handler) {
|
||||
s.handler = h
|
||||
}
|
||||
|
||||
// SetLogger implements `Engine#SetLogger` method.
|
||||
func (s *Server) SetLogger(l *log.Logger) {
|
||||
s.logger = l
|
||||
}
|
||||
|
||||
// Start implements `Engine#Start` method.
|
||||
func (s *Server) Start() {
|
||||
certfile := s.config.TLSCertfile
|
||||
keyfile := s.config.TLSKeyfile
|
||||
@ -94,6 +101,7 @@ func (s *Server) Start() {
|
||||
}
|
||||
}
|
||||
|
||||
// ServeHTTP implements `http.Handler` interface.
|
||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// Request
|
||||
req := s.pool.request.Get().(*Request)
|
||||
|
@ -3,20 +3,24 @@ package standard
|
||||
import "net/url"
|
||||
|
||||
type (
|
||||
// URL implements `engine.URL`.
|
||||
URL struct {
|
||||
*url.URL
|
||||
query url.Values
|
||||
}
|
||||
)
|
||||
|
||||
func (u *URL) SetPath(path string) {
|
||||
u.URL.Path = path
|
||||
}
|
||||
|
||||
// Path implements `URL#Path` method.
|
||||
func (u *URL) Path() string {
|
||||
return u.URL.Path
|
||||
}
|
||||
|
||||
// SetPath implements `URL#SetPath` method.
|
||||
func (u *URL) SetPath(path string) {
|
||||
u.URL.Path = path
|
||||
}
|
||||
|
||||
// QueryValue implements `URL#QueryValue` method.
|
||||
func (u *URL) QueryValue(name string) string {
|
||||
if u.query == nil {
|
||||
u.query = u.Query()
|
||||
|
2
glide.lock
generated
2
glide.lock
generated
@ -1,5 +1,5 @@
|
||||
hash: f220137e9ccd9aaf3051be33c3c23ea8abd2c40df6cf96175c3994d482b5e007
|
||||
updated: 2016-03-14T08:16:01.763706114-07:00
|
||||
updated: 2016-03-14T18:03:44.054071074-07:00
|
||||
imports:
|
||||
- name: github.com/klauspost/compress
|
||||
version: 006acde2c5d283d2f8b8aa03d8f0cd2891c680cf
|
||||
|
@ -60,6 +60,10 @@ func (r *Request) Header() engine.Header {
|
||||
// return r.request.ProtoMinor()
|
||||
// }
|
||||
|
||||
func (r *Request) UserAgent() string {
|
||||
return r.request.UserAgent()
|
||||
}
|
||||
|
||||
func (r *Request) RemoteAddress() string {
|
||||
return r.request.RemoteAddr
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user