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

Changed constants

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2015-04-05 21:49:55 -07:00
parent 7b433cdd74
commit 86138ed18e
4 changed files with 51 additions and 51 deletions

View File

@ -11,7 +11,7 @@ import (
func TestContext(t *testing.T) {
b, _ := json.Marshal(u1)
r, _ := http.NewRequest(MethodPOST, "/users/1", bytes.NewReader(b))
r, _ := http.NewRequest(POST, "/users/1", bytes.NewReader(b))
c := &Context{
Response: &response{ResponseWriter: httptest.NewRecorder()},
Request: r,

54
echo.go
View File

@ -23,15 +23,15 @@ type (
)
const (
MethodCONNECT = "CONNECT"
MethodDELETE = "DELETE"
MethodGET = "GET"
MethodHEAD = "HEAD"
MethodOPTIONS = "OPTIONS"
MethodPATCH = "PATCH"
MethodPOST = "POST"
MethodPUT = "PUT"
MethodTRACE = "TRACE"
CONNECT = "CONNECT"
DELETE = "DELETE"
GET = "GET"
HEAD = "HEAD"
OPTIONS = "OPTIONS"
PATCH = "PATCH"
POST = "POST"
PUT = "PUT"
TRACE = "TRACE"
MIMEJSON = "application/json"
MIMEText = "text/plain"
@ -47,15 +47,15 @@ const (
var (
methods = [...]string{
MethodCONNECT,
MethodDELETE,
MethodGET,
MethodHEAD,
MethodOPTIONS,
MethodPATCH,
MethodPOST,
MethodPUT,
MethodTRACE,
CONNECT,
DELETE,
GET,
HEAD,
OPTIONS,
PATCH,
POST,
PUT,
TRACE,
}
// Errors
@ -123,47 +123,47 @@ func (e *Echo) Use(m ...Middleware) {
// Connect adds a CONNECT route > handler to the router.
func (e *Echo) Connect(path string, h Handler) {
e.add(MethodCONNECT, path, h)
e.add(CONNECT, path, h)
}
// Delete adds a DELETE route > handler to the router.
func (e *Echo) Delete(path string, h Handler) {
e.add(MethodDELETE, path, h)
e.add(DELETE, path, h)
}
// Get adds a GET route > handler to the router.
func (e *Echo) Get(path string, h Handler) {
e.add(MethodGET, path, h)
e.add(GET, path, h)
}
// Head adds a HEAD route > handler to the router.
func (e *Echo) Head(path string, h Handler) {
e.add(MethodHEAD, path, h)
e.add(HEAD, path, h)
}
// Options adds an OPTIONS route > handler to the router.
func (e *Echo) Options(path string, h Handler) {
e.add(MethodOPTIONS, path, h)
e.add(OPTIONS, path, h)
}
// Patch adds a PATCH route > handler to the router.
func (e *Echo) Patch(path string, h Handler) {
e.add(MethodPATCH, path, h)
e.add(PATCH, path, h)
}
// Post adds a POST route > handler to the router.
func (e *Echo) Post(path string, h Handler) {
e.add(MethodPOST, path, h)
e.add(POST, path, h)
}
// Put adds a PUT route > handler to the router.
func (e *Echo) Put(path string, h Handler) {
e.add(MethodPUT, path, h)
e.add(PUT, path, h)
}
// Trace adds a TRACE route > handler to the router.
func (e *Echo) Trace(path string, h Handler) {
e.add(MethodTRACE, path, h)
e.add(TRACE, path, h)
}
func (e *Echo) add(method, path string, h Handler) {

View File

@ -32,7 +32,7 @@ func TestEchoIndex(t *testing.T) {
e := New()
e.Index("example/public/index.html")
w := httptest.NewRecorder()
r, _ := http.NewRequest(MethodGET, "/", nil)
r, _ := http.NewRequest(GET, "/", nil)
e.ServeHTTP(w, r)
if w.Code != 200 {
t.Errorf("status code should be 200, found %d", w.Code)
@ -43,7 +43,7 @@ func TestEchoStatic(t *testing.T) {
e := New()
e.Static("/js", "example/public/js")
w := httptest.NewRecorder()
r, _ := http.NewRequest(MethodGET, "/js/main.js", nil)
r, _ := http.NewRequest(GET, "/js/main.js", nil)
e.ServeHTTP(w, r)
if w.Code != 200 {
t.Errorf("status code should be 200, found %d", w.Code)
@ -96,7 +96,7 @@ func TestEchoMiddleware(t *testing.T) {
})
w := httptest.NewRecorder()
r, _ := http.NewRequest(MethodGET, "/hello", nil)
r, _ := http.NewRequest(GET, "/hello", nil)
e.ServeHTTP(w, r)
if b.String() != "abcdef" {
t.Errorf("buffer should be abcdef, found %s", b.String())
@ -114,7 +114,7 @@ func TestEchoHandler(t *testing.T) {
c.Text(http.StatusOK, "1")
})
w := httptest.NewRecorder()
r, _ := http.NewRequest(MethodGET, "/1", nil)
r, _ := http.NewRequest(GET, "/1", nil)
e.ServeHTTP(w, r)
if w.Body.String() != "1" {
t.Error("body should be 1")
@ -125,7 +125,7 @@ func TestEchoHandler(t *testing.T) {
w.Write([]byte("2"))
}))
w = httptest.NewRecorder()
r, _ = http.NewRequest(MethodGET, "/2", nil)
r, _ = http.NewRequest(GET, "/2", nil)
e.ServeHTTP(w, r)
if w.Body.String() != "2" {
t.Error("body should be 2")
@ -136,7 +136,7 @@ func TestEchoHandler(t *testing.T) {
w.Write([]byte("3"))
})
w = httptest.NewRecorder()
r, _ = http.NewRequest(MethodGET, "/3", nil)
r, _ = http.NewRequest(GET, "/3", nil)
e.ServeHTTP(w, r)
if w.Body.String() != "3" {
t.Error("body should be 3")
@ -165,7 +165,7 @@ func TestEchoSubGroup(t *testing.T) {
g.Get("/home", func(*Context) {})
w := httptest.NewRecorder()
r, _ := http.NewRequest(MethodGET, "/users", nil)
r, _ := http.NewRequest(GET, "/users", nil)
e.ServeHTTP(w, r)
if b.String() != "1" {
t.Errorf("should only execute middleware 1, executed %s", b.String())
@ -173,7 +173,7 @@ func TestEchoSubGroup(t *testing.T) {
b.Reset()
w = httptest.NewRecorder()
r, _ = http.NewRequest(MethodGET, "/sub/home", nil)
r, _ = http.NewRequest(GET, "/sub/home", nil)
e.ServeHTTP(w, r)
if b.String() != "12" {
t.Errorf("should execute middleware 1 & 2, executed %s", b.String())
@ -181,7 +181,7 @@ func TestEchoSubGroup(t *testing.T) {
b.Reset()
w = httptest.NewRecorder()
r, _ = http.NewRequest(MethodGET, "/group/home", nil)
r, _ = http.NewRequest(GET, "/group/home", nil)
e.ServeHTTP(w, r)
if b.String() != "3" {
t.Errorf("should execute middleware 3, executed %s", b.String())
@ -205,7 +205,7 @@ func TestEchoNotFound(t *testing.T) {
e := New()
// Default NotFound handler
r, _ := http.NewRequest(MethodGET, "/files", nil)
r, _ := http.NewRequest(GET, "/files", nil)
w := httptest.NewRecorder()
e.ServeHTTP(w, r)
if w.Code != http.StatusNotFound {

View File

@ -277,8 +277,8 @@ var api = []route{
func TestRouterStatic(t *testing.T) {
r := New().Router
r.Add(MethodGET, "/folders/files/echo.gif", func(c *Context) {}, nil)
h, _, _ := r.Find(MethodGET, "/folders/files/echo.gif")
r.Add(GET, "/folders/files/echo.gif", func(c *Context) {}, nil)
h, _, _ := r.Find(GET, "/folders/files/echo.gif")
if h == nil {
t.Fatal("handle not found")
}
@ -286,8 +286,8 @@ func TestRouterStatic(t *testing.T) {
func TestRouterParam(t *testing.T) {
r := New().Router
r.Add(MethodGET, "/users/:id", func(c *Context) {}, nil)
h, c, _ := r.Find(MethodGET, "/users/1")
r.Add(GET, "/users/:id", func(c *Context) {}, nil)
h, c, _ := r.Find(GET, "/users/1")
if h == nil {
t.Fatal("handle not found")
}
@ -298,8 +298,8 @@ func TestRouterParam(t *testing.T) {
func TestRouterTwoParam(t *testing.T) {
r := New().Router
r.Add(MethodGET, "/users/:uid/files/:fid", func(c *Context) {}, nil)
h, c, _ := r.Find(MethodGET, "/users/1/files/1")
r.Add(GET, "/users/:uid/files/:fid", func(c *Context) {}, nil)
h, c, _ := r.Find(GET, "/users/1/files/1")
if h == nil {
t.Fatal("handle not found")
}
@ -313,8 +313,8 @@ func TestRouterTwoParam(t *testing.T) {
func TestRouterCatchAll(t *testing.T) {
r := New().Router
r.Add(MethodGET, "/static/*", func(c *Context) {}, nil)
h, _, _ := r.Find(MethodGET, "/static/*")
r.Add(GET, "/static/*", func(c *Context) {}, nil)
h, _, _ := r.Find(GET, "/static/*")
if h == nil {
t.Fatal("handle not found")
}
@ -322,8 +322,8 @@ func TestRouterCatchAll(t *testing.T) {
func TestRouterMicroParam(t *testing.T) {
r := New().Router
r.Add(MethodGET, "/:a/:b/:c", func(c *Context) {}, nil)
h, c, _ := r.Find(MethodGET, "/1/2/3")
r.Add(GET, "/:a/:b/:c", func(c *Context) {}, nil)
h, c, _ := r.Find(GET, "/1/2/3")
if h == nil {
t.Fatal("handle not found")
}
@ -358,15 +358,15 @@ func TestRouterAPI(t *testing.T) {
func TestRouterServeHTTP(t *testing.T) {
r := New().Router
r.Add(MethodGET, "/users", func(c *Context) {}, nil)
r.Add(GET, "/users", func(c *Context) {}, nil)
// OK
req, _ := http.NewRequest(MethodGET, "/users", nil)
req, _ := http.NewRequest(GET, "/users", nil)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
// NotFound handler
req, _ = http.NewRequest(MethodGET, "/files", nil)
req, _ = http.NewRequest(GET, "/files", nil)
w = httptest.NewRecorder()
r.ServeHTTP(w, req)
}