mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-24 02:32:17 +08:00
Merge branch 'master' into comment
This commit is contained in:
commit
45869f941e
@ -13,10 +13,10 @@ func init() {
|
|||||||
|
|
||||||
// Define your handlers
|
// Define your handlers
|
||||||
r.GET("/", func(c *gin.Context) {
|
r.GET("/", func(c *gin.Context) {
|
||||||
c.String(200, "Hello World!")
|
c.String(http.StatusOK, "Hello World!")
|
||||||
})
|
})
|
||||||
r.GET("/ping", func(c *gin.Context) {
|
r.GET("/ping", func(c *gin.Context) {
|
||||||
c.String(200, "pong")
|
c.String(http.StatusOK, "pong")
|
||||||
})
|
})
|
||||||
|
|
||||||
// Handle all requests using net/http
|
// Handle all requests using net/http
|
||||||
|
2
gin.go
2
gin.go
@ -268,7 +268,7 @@ func (engine *Engine) Run(addr ...string) (err error) {
|
|||||||
// RunTLS attaches the router to a http.Server and starts listening and serving HTTPS (secure) requests.
|
// RunTLS attaches the router to a http.Server and starts listening and serving HTTPS (secure) requests.
|
||||||
// It is a shortcut for http.ListenAndServeTLS(addr, certFile, keyFile, router)
|
// It is a shortcut for http.ListenAndServeTLS(addr, certFile, keyFile, router)
|
||||||
// Note: this method will block the calling goroutine indefinitely unless an error happens.
|
// Note: this method will block the calling goroutine indefinitely unless an error happens.
|
||||||
func (engine *Engine) RunTLS(addr string, certFile string, keyFile string) (err error) {
|
func (engine *Engine) RunTLS(addr, certFile, keyFile string) (err error) {
|
||||||
debugPrint("Listening and serving HTTPS on %s\n", addr)
|
debugPrint("Listening and serving HTTPS on %s\n", addr)
|
||||||
defer func() { debugPrintError(err) }()
|
defer func() { debugPrintError(err) }()
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc {
|
|||||||
path = path + "?" + raw
|
path = path + "?" + raw
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(out, "[GIN] %v |%s %3d %s| %13v | %15s |%s %s %-7s %s\n%s",
|
fmt.Fprintf(out, "[GIN] %v |%s %3d %s| %13v | %15s |%s %-7s %s %s\n%s",
|
||||||
end.Format("2006/01/02 - 15:04:05"),
|
end.Format("2006/01/02 - 15:04:05"),
|
||||||
statusColor, statusCode, reset,
|
statusColor, statusCode, reset,
|
||||||
latency,
|
latency,
|
||||||
|
@ -358,23 +358,23 @@ func TestRouterNotFound(t *testing.T) {
|
|||||||
testRoutes := []struct {
|
testRoutes := []struct {
|
||||||
route string
|
route string
|
||||||
code int
|
code int
|
||||||
header string
|
location string
|
||||||
}{
|
}{
|
||||||
{"/path/", 301, "map[Location:[/path]]"}, // TSR -/
|
{"/path/", 301, "/path"}, // TSR -/
|
||||||
{"/dir", 301, "map[Location:[/dir/]]"}, // TSR +/
|
{"/dir", 301, "/dir/"}, // TSR +/
|
||||||
{"", 301, "map[Location:[/]]"}, // TSR +/
|
{"", 301, "/"}, // TSR +/
|
||||||
{"/PATH", 301, "map[Location:[/path]]"}, // Fixed Case
|
{"/PATH", 301, "/path"}, // Fixed Case
|
||||||
{"/DIR/", 301, "map[Location:[/dir/]]"}, // Fixed Case
|
{"/DIR/", 301, "/dir/"}, // Fixed Case
|
||||||
{"/PATH/", 301, "map[Location:[/path]]"}, // Fixed Case -/
|
{"/PATH/", 301, "/path"}, // Fixed Case -/
|
||||||
{"/DIR", 301, "map[Location:[/dir/]]"}, // Fixed Case +/
|
{"/DIR", 301, "/dir/"}, // Fixed Case +/
|
||||||
{"/../path", 301, "map[Location:[/path]]"}, // CleanPath
|
{"/../path", 301, "/path"}, // CleanPath
|
||||||
{"/nope", 404, ""}, // NotFound
|
{"/nope", 404, ""}, // NotFound
|
||||||
}
|
}
|
||||||
for _, tr := range testRoutes {
|
for _, tr := range testRoutes {
|
||||||
w := performRequest(router, "GET", tr.route)
|
w := performRequest(router, "GET", tr.route)
|
||||||
assert.Equal(t, w.Code, tr.code)
|
assert.Equal(t, w.Code, tr.code)
|
||||||
if w.Code != 404 {
|
if w.Code != 404 {
|
||||||
assert.Equal(t, fmt.Sprint(w.Header()), tr.header)
|
assert.Equal(t, fmt.Sprint(w.Header().Get("Location")), tr.location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user