Kaynağa Gözat

unify the http method conventions

tags/v0.9.0
jimzhan 9 yıl önce
ebeveyn
işleme
be698a784d
8 değiştirilmiş dosya ile 48 ekleme ve 48 silme
  1. +3
    -3
      README.md
  2. +5
    -5
      example/main.go
  3. +1
    -1
      middleware/cache_test.go
  4. +1
    -1
      middleware/compress_test.go
  5. +1
    -1
      middleware/header_test.go
  6. +1
    -1
      middleware/static_test.go
  7. +15
    -15
      server.go
  8. +21
    -21
      server_test.go

+ 3
- 3
README.md Dosyayı Görüntüle

@@ -42,7 +42,7 @@ import (

func main() {
app := rex.New()
app.GET("/", func(w http.ResponseWriter, r *http.Request) {
app.Get("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Hello World")
})
app.Run()
@@ -82,7 +82,7 @@ func main() {
env.Set("PORT", 9394)

app := rex.New()
app.GET("/", index)
app.Get("/", index)
app.Run()
}
```
@@ -117,7 +117,7 @@ Using prefixed (aka. subrouter) router is exactly same as the main one:

```go
app := rex.New()
app.GET("/", func(w http.ResponseWriter, r *http.Request) {
app.Get("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "index page")
})


+ 5
- 5
example/main.go Dosyayı Görüntüle

@@ -87,14 +87,14 @@ func remove(w http.ResponseWriter, r *http.Request) {
func main() {
app := rex.New()
app.Use(livereload.Middleware)
app.GET("/", Index)
app.Get("/", Index)

api := app.Group("/v1/")
api.Use(JSON)
api.GET("/", fetch)
api.POST("/", create)
api.PUT("/", update)
api.DELETE("/", remove)
api.Get("/", fetch)
api.Post("/", create)
api.Put("/", update)
api.Delete("/", remove)

app.Run()
}

+ 1
- 1
middleware/cache_test.go Dosyayı Görüntüle

@@ -13,7 +13,7 @@ import (
func TestNoCache(t *testing.T) {
app := rex.New()
app.Use(NoCache)
app.GET("/", func(w http.ResponseWriter, r *http.Request) {
app.Get("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "app")
})


+ 1
- 1
middleware/compress_test.go Dosyayı Görüntüle

@@ -14,7 +14,7 @@ func TestCompress(t *testing.T) {

app := rex.New()
app.Use(Compress)
app.GET("/", func(w http.ResponseWriter, r *http.Request) {
app.Get("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "app")
})


+ 1
- 1
middleware/header_test.go Dosyayı Görüntüle

@@ -16,7 +16,7 @@ func TestHeader(t *testing.T) {

app := rex.New()
app.Use(Header(values))
app.GET("/", func(w http.ResponseWriter, r *http.Request) {
app.Get("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "app")
})


+ 1
- 1
middleware/static_test.go Dosyayı Görüntüle

@@ -19,7 +19,7 @@ func TestStatic(t *testing.T) {
app := rex.New()
app.Use(Static(tempdir))
prefix := path.Join("/", path.Base(path.Dir(filename)))
app.GET(prefix, func(w http.ResponseWriter, r *http.Request) {
app.Get(prefix, func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "app")
})


+ 15
- 15
server.go Dosyayı Görüntüle

@@ -127,52 +127,52 @@ func (self *server) Use(module func(http.Handler) http.Handler) {
self.middleware.stack = append(self.middleware.stack, module)
}

// GET is a shortcut for mux.HandleFunc(pattern, handler).Methods("GET"),
// Get is a shortcut for mux.HandleFunc(pattern, handler).Methods("GET"),
// it also fetch the full function name of the handler (with package) to name the route.
func (self *server) GET(pattern string, handler interface{}) {
func (self *server) Get(pattern string, handler interface{}) {
self.register(pattern, handler, "GET")
}

// HEAD is a shortcut for mux.HandleFunc(pattern, handler).Methods("HEAD")
// Head is a shortcut for mux.HandleFunc(pattern, handler).Methods("HEAD")
// it also fetch the full function name of the handler (with package) to name the route.
func (self *server) HEAD(pattern string, handler interface{}) {
func (self *server) Head(pattern string, handler interface{}) {
self.register(pattern, handler, "HEAD")
}

// OPTIONS is a shortcut for mux.HandleFunc(pattern, handler).Methods("OPTIONS")
// Options is a shortcut for mux.HandleFunc(pattern, handler).Methods("OPTIONS")
// it also fetch the full function name of the handler (with package) to name the route.
// NOTE method OPTIONS is **NOT** cachable, beware of what you are going to do.
func (self *server) OPTIONS(pattern string, handler interface{}) {
func (self *server) Options(pattern string, handler interface{}) {
self.register(pattern, handler, "OPTIONS")
}

// POST is a shortcut for mux.HandleFunc(pattern, handler).Methods("POST")
// it also fetch the full function name of the handler (with package) to name the route.
func (self *server) POST(pattern string, handler interface{}) {
func (self *server) Post(pattern string, handler interface{}) {
self.register(pattern, handler, "POST")
}

// PUT is a shortcut for mux.HandleFunc(pattern, handler).Methods("PUT")
// Put is a shortcut for mux.HandleFunc(pattern, handler).Methods("PUT")
// it also fetch the full function name of the handler (with package) to name the route.
func (self *server) PUT(pattern string, handler interface{}) {
func (self *server) Put(pattern string, handler interface{}) {
self.register(pattern, handler, "PUT")
}

// DELETE is a shortcut for mux.HandleFunc(pattern, handler).Methods("DELETE")
// Delete is a shortcut for mux.HandleFunc(pattern, handler).Methods("DELETE")
// it also fetch the full function name of the handler (with package) to name the route.
func (self *server) DELETE(pattern string, handler interface{}) {
func (self *server) Delete(pattern string, handler interface{}) {
self.register(pattern, handler, "DELETE")
}

// TRACE is a shortcut for mux.HandleFunc(pattern, handler).Methods("TRACE")
// Trace is a shortcut for mux.HandleFunc(pattern, handler).Methods("TRACE")
// it also fetch the full function name of the handler (with package) to name the route.
func (self *server) TRACE(pattern string, handler interface{}) {
func (self *server) Trace(pattern string, handler interface{}) {
self.register(pattern, handler, "TRACE")
}

// CONNECT is a shortcut for mux.HandleFunc(pattern, handler).Methods("CONNECT")
// Connect is a shortcut for mux.HandleFunc(pattern, handler).Methods("CONNECT")
// it also fetch the full function name of the handler (with package) to name the route.
func (self *server) CONNECT(pattern string, handler interface{}) {
func (self *server) Connect(pattern string, handler interface{}) {
self.register(pattern, handler, "CONNECT")
}


+ 21
- 21
server_test.go Dosyayı Görüntüle

@@ -123,7 +123,7 @@ func TestAny(t *testing.T) {
func TestName(t *testing.T) {
Convey("rex.Name", t, func() {
app := New()
app.GET("/login", func(w http.ResponseWriter, r *http.Request) {
app.Get("/login", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})

@@ -134,9 +134,9 @@ func TestName(t *testing.T) {
})
}

func TestGET(t *testing.T) {
func TestGet(t *testing.T) {
app := New()
app.GET("/", func(w http.ResponseWriter, r *http.Request) {
app.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Powered-By", "rex")
})

@@ -150,9 +150,9 @@ func TestGET(t *testing.T) {
})
}

func TestHEAD(t *testing.T) {
func TestHead(t *testing.T) {
app := New()
app.HEAD("/", func(w http.ResponseWriter, r *http.Request) {
app.Head("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Powered-By", "rex")
})

@@ -166,9 +166,9 @@ func TestHEAD(t *testing.T) {
})
}

func TestOPTIONS(t *testing.T) {
func TestOptions(t *testing.T) {
app := New()
app.OPTIONS("/", func(w http.ResponseWriter, r *http.Request) {
app.Options("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Powered-By", "rex")
})

@@ -182,9 +182,9 @@ func TestOPTIONS(t *testing.T) {
})
}

func TestPOST(t *testing.T) {
func TestPost(t *testing.T) {
app := New()
app.POST("/", func(w http.ResponseWriter, r *http.Request) {
app.Post("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Powered-By", "rex")
w.Header().Set("Content-Type", "application/json")
})
@@ -200,9 +200,9 @@ func TestPOST(t *testing.T) {
})
}

func TestPUT(t *testing.T) {
func TestPut(t *testing.T) {
app := New()
app.PUT("/", func(w http.ResponseWriter, r *http.Request) {
app.Put("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Powered-By", "rex")
w.Header().Set("Content-Type", "application/json")
})
@@ -218,9 +218,9 @@ func TestPUT(t *testing.T) {
})
}

func TestDELETE(t *testing.T) {
func TestDelete(t *testing.T) {
app := New()
app.DELETE("/", func(w http.ResponseWriter, r *http.Request) {
app.Delete("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Powered-By", "rex")
w.Header().Set("Content-Type", "application/json")
})
@@ -236,9 +236,9 @@ func TestDELETE(t *testing.T) {
})
}

func TestCONNECT(t *testing.T) {
func TestConnect(t *testing.T) {
app := New()
app.CONNECT("/", func(w http.ResponseWriter, r *http.Request) {
app.Connect("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Powered-By", "rex")
})

@@ -252,9 +252,9 @@ func TestCONNECT(t *testing.T) {
})
}

func TestTRACE(t *testing.T) {
func TestTrace(t *testing.T) {
app := New()
app.TRACE("/", func(w http.ResponseWriter, r *http.Request) {
app.Trace("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Powered-By", "rex")
})

@@ -270,11 +270,11 @@ func TestTRACE(t *testing.T) {

func TestGroup(t *testing.T) {
app := New()
app.GET("/", func(w http.ResponseWriter, r *http.Request) {
app.Get("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "index")
})
user := app.Group("/users")
user.GET("/", func(w http.ResponseWriter, r *http.Request) {
user.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Powered-By", "rex")
})

@@ -317,7 +317,7 @@ func TestFileServer(t *testing.T) {

func TestUse(t *testing.T) {
app := New()
app.GET("/", func(w http.ResponseWriter, r *http.Request) {
app.Get("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "index")
})
app.Use(func(next http.Handler) http.Handler {
@@ -337,7 +337,7 @@ func TestUse(t *testing.T) {
func TestVars(t *testing.T) {
Convey("rex.Vars", t, func() {
app := New()
app.GET("/users/{id}", func(w http.ResponseWriter, r *http.Request) {
app.Get("/users/{id}", func(w http.ResponseWriter, r *http.Request) {
vars := app.Vars(r)
So(vars["id"], ShouldEqual, "123")
})

Yükleniyor…
İptal
Kaydet