1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-24 08:22:21 +02:00

Fixed package dependencies

Signed-off-by: Vishal Rana <vishal.rana@verizon.com>
This commit is contained in:
Vishal Rana 2016-02-09 13:37:38 -08:00
parent 92307b9a1f
commit 8444488a2b
8 changed files with 75 additions and 73 deletions

View File

@ -3,14 +3,13 @@
# [Echo](http://labstack.com/echo) [![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/labstack/echo) [![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/labstack/echo/master/LICENSE) [![Build Status](http://img.shields.io/travis/labstack/echo.svg?style=flat-square)](https://travis-ci.org/labstack/echo) [![Coverage Status](http://img.shields.io/coveralls/labstack/echo.svg?style=flat-square)](https://coveralls.io/r/labstack/echo) [![Join the chat at https://gitter.im/labstack/echo](https://img.shields.io/badge/gitter-join%20chat-brightgreen.svg?style=flat-square)](https://gitter.im/labstack/echo)
## A fast and unfancy micro web framework for Go.
A fast and unfancy micro web framework for Go.
```go
package main
import (
"github.com/labstack/echo"
"github.com/labstack/echo/engine"
"github.com/labstack/echo/engine/fasthttp"
mw "github.com/labstack/echo/middleware"
)
@ -26,14 +25,11 @@ func main() {
})
// FastHTTP
e.RunEngine(fasthttp.NewServer(&engine.Config{
Address: ":4444",
}, e.Handle, e.Logger()))
e.Run(fasthttp.New(":4444", e))
// Standard
// e.Run(":4444")
// e.Run(standard.New(":4444"))
}
```
## Performance

View File

@ -8,7 +8,6 @@ import (
"time"
"github.com/labstack/echo/engine"
"github.com/labstack/echo/logger"
"net/url"
@ -46,7 +45,7 @@ type (
NoContent(int) error
Redirect(int, string) error
Error(err error)
Logger() logger.Logger
Logger() Logger
Object() *context
}
@ -303,7 +302,7 @@ func (c *context) Error(err error) {
}
// Logger returns the `Logger` instance.
func (c *context) Logger() logger.Logger {
func (c *context) Logger() Logger {
return c.echo.logger
}

50
echo.go
View File

@ -17,8 +17,6 @@ import (
"encoding/xml"
"github.com/labstack/echo/engine"
"github.com/labstack/echo/engine/standard"
"github.com/labstack/echo/logger"
"github.com/labstack/gommon/log"
)
@ -37,7 +35,7 @@ type (
hook engine.HandlerFunc
autoIndex bool
router *Router
logger logger.Logger
logger Logger
}
Route struct {
@ -83,6 +81,24 @@ type (
Renderer interface {
Render(w io.Writer, name string, data interface{}) error
}
// Logger is the interface that declares Echo's logging system.
Logger interface {
Debug(...interface{})
Debugf(string, ...interface{})
Info(...interface{})
Infof(string, ...interface{})
Warn(...interface{})
Warnf(string, ...interface{})
Error(...interface{})
Errorf(string, ...interface{})
Fatal(...interface{})
Fatalf(string, ...interface{})
}
)
const (
@ -226,12 +242,12 @@ func (e *Echo) Router() *Router {
}
// SetLogger sets the logger instance.
func (e *Echo) SetLogger(logger logger.Logger) {
e.logger = logger
func (e *Echo) SetLogger(l Logger) {
e.logger = l
}
// Logger returns the logger instance.
func (e *Echo) Logger() logger.Logger {
func (e *Echo) Logger() Logger {
return e.logger
}
@ -511,7 +527,7 @@ func (e *Echo) Routes() []Route {
return e.router.routes
}
func (e *Echo) Handle(req engine.Request, res engine.Response) {
func (e *Echo) ServeHTTP(req engine.Request, res engine.Response) {
if e.hook != nil {
e.hook(req, res)
}
@ -543,24 +559,8 @@ func (e *Echo) Handle(req engine.Request, res engine.Response) {
// return s
// }
// Run runs a server.
func (e *Echo) Run(addr string) {
c := &engine.Config{Address: addr}
e.RunEngine(standard.NewServer(c, e.Handle, e.logger))
}
// RunTLS runs a server with TLS configuration.
func (e *Echo) RunTLS(addr, certfile, keyfile string) {
c := &engine.Config{
Address: addr,
TLSCertfile: certfile,
TLSKeyfile: keyfile,
}
e.RunEngine(standard.NewServer(c, e.Handle, e.logger))
}
// RunEngine runs a custom engine.
func (*Echo) RunEngine(e engine.Engine) {
// Run starts the HTTP engine.
func (*Echo) Run(e engine.Engine) {
e.Start()
}

View File

@ -5,8 +5,8 @@ package fasthttp
import (
"io"
"github.com/labstack/echo"
"github.com/labstack/echo/engine"
"github.com/labstack/echo/logger"
"github.com/valyala/fasthttp"
)
@ -18,11 +18,11 @@ type (
size int64
committed bool
writer io.Writer
logger logger.Logger
logger echo.Logger
}
)
func NewResponse(c *fasthttp.RequestCtx, l logger.Logger) *Response {
func NewResponse(c *fasthttp.RequestCtx, l echo.Logger) *Response {
return &Response{
context: c,
header: &ResponseHeader{c.Response.Header},

View File

@ -5,8 +5,8 @@ package fasthttp
import (
"net/http"
"github.com/labstack/echo"
"github.com/labstack/echo/engine"
"github.com/labstack/echo/logger"
"github.com/valyala/fasthttp"
)
@ -15,16 +15,30 @@ type (
*http.Server
config *engine.Config
handler engine.HandlerFunc
logger logger.Logger
logger echo.Logger
}
)
func NewServer(c *engine.Config, h engine.HandlerFunc, l logger.Logger) *Server {
func New(addr string, e *echo.Echo) *Server {
c := &engine.Config{Address: addr}
return NewConfig(c, e)
}
func NewTLS(addr, certfile, keyfile string, e *echo.Echo) *Server {
c := &engine.Config{
Address: addr,
TLSCertfile: certfile,
TLSKeyfile: keyfile,
}
return NewConfig(c, e)
}
func NewConfig(c *engine.Config, e *echo.Echo) *Server {
return &Server{
Server: new(http.Server),
config: c,
handler: h,
logger: l,
handler: e.ServeHTTP,
logger: e.Logger(),
}
}

View File

@ -4,8 +4,8 @@ import (
"io"
"net/http"
"github.com/labstack/echo"
"github.com/labstack/echo/engine"
"github.com/labstack/echo/logger"
)
type (
@ -16,11 +16,11 @@ type (
size int64
committed bool
writer io.Writer
logger logger.Logger
logger echo.Logger
}
)
func NewResponse(w http.ResponseWriter, l logger.Logger) *Response {
func NewResponse(w http.ResponseWriter, l echo.Logger) *Response {
return &Response{
response: w,
header: &Header{w.Header()},

View File

@ -4,8 +4,8 @@ import (
"net/http"
"sync"
"github.com/labstack/echo"
"github.com/labstack/echo/engine"
"github.com/labstack/echo/logger"
)
type (
@ -14,7 +14,7 @@ type (
config *engine.Config
handler engine.HandlerFunc
pool *Pool
logger logger.Logger
logger echo.Logger
}
Pool struct {
@ -25,11 +25,25 @@ type (
}
)
func NewServer(c *engine.Config, h engine.HandlerFunc, l logger.Logger) *Server {
func New(addr string, e *echo.Echo) *Server {
c := &engine.Config{Address: addr}
return NewConfig(c, e)
}
func NewTLS(addr, certfile, keyfile string, e *echo.Echo) *Server {
c := &engine.Config{
Address: addr,
TLSCertfile: certfile,
TLSKeyfile: keyfile,
}
return NewConfig(c, e)
}
func NewConfig(c *engine.Config, e *echo.Echo) *Server {
return &Server{
Server: new(http.Server),
config: c,
handler: h,
handler: e.ServeHTTP,
pool: &Pool{
request: sync.Pool{
New: func() interface{} {
@ -38,7 +52,7 @@ func NewServer(c *engine.Config, h engine.HandlerFunc, l logger.Logger) *Server
},
response: sync.Pool{
New: func() interface{} {
return &Response{logger: l}
return &Response{logger: e.Logger()}
},
},
header: sync.Pool{
@ -52,7 +66,7 @@ func NewServer(c *engine.Config, h engine.HandlerFunc, l logger.Logger) *Server
},
},
},
logger: l,
logger: e.Logger(),
}
}

View File

@ -1,21 +0,0 @@
package logger
type (
// Logger is the interface that declares Echo's logging system.
Logger interface {
Debug(...interface{})
Debugf(string, ...interface{})
Info(...interface{})
Infof(string, ...interface{})
Warn(...interface{})
Warnf(string, ...interface{})
Error(...interface{})
Errorf(string, ...interface{})
Fatal(...interface{})
Fatalf(string, ...interface{})
}
)