diff --git a/response_writer.go b/response_writer.go index a40f5ba0..2c97e766 100644 --- a/response_writer.go +++ b/response_writer.go @@ -16,32 +16,6 @@ const ( defaultStatus = 200 ) -type ResponseWriter interface { - http.ResponseWriter - http.Hijacker - http.Flusher - http.CloseNotifier - - // Returns the HTTP response status code of the current request. - Status() int - - // Returns the number of bytes already written into the response http body. - // See Written() - Size() int - - // Writes the string into the response body. - WriteString(string) (int, error) - - // Returns true if the response body was already written. - Written() bool - - // Forces to write the http header (status code + headers). - WriteHeaderNow() - - // get the http.Pusher for server push - Pusher() http.Pusher -} - type responseWriter struct { http.ResponseWriter size int @@ -115,10 +89,3 @@ func (w *responseWriter) CloseNotify() <-chan bool { func (w *responseWriter) Flush() { w.ResponseWriter.(http.Flusher).Flush() } - -func (w *responseWriter) Pusher() (pusher http.Pusher) { - if pusher, ok := w.ResponseWriter.(http.ResponseWriter).(http.Pusher); ok { - return pusher - } - return nil -} diff --git a/response_writer_1.7.go b/response_writer_1.7.go new file mode 100644 index 00000000..0ffa35b8 --- /dev/null +++ b/response_writer_1.7.go @@ -0,0 +1,33 @@ +// +build go1.7 + +// Copyright 2018 Gin Core Team. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package gin + +import "net/http" + +// ResponseWriter ... +type ResponseWriter interface { + http.ResponseWriter + http.Hijacker + http.Flusher + http.CloseNotifier + + // Returns the HTTP response status code of the current request. + Status() int + + // Returns the number of bytes already written into the response http body. + // See Written() + Size() int + + // Writes the string into the response body. + WriteString(string) (int, error) + + // Returns true if the response body was already written. + Written() bool + + // Forces to write the http header (status code + headers). + WriteHeaderNow() +} diff --git a/response_writer_1.8.go b/response_writer_1.8.go new file mode 100644 index 00000000..c80dc81e --- /dev/null +++ b/response_writer_1.8.go @@ -0,0 +1,43 @@ +// +build !go1.7 + +// Copyright 2018 Gin Core Team. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package gin + +import "net/http" + +// ResponseWriter ... +type ResponseWriter interface { + http.ResponseWriter + http.Hijacker + http.Flusher + http.CloseNotifier + + // Returns the HTTP response status code of the current request. + Status() int + + // Returns the number of bytes already written into the response http body. + // See Written() + Size() int + + // Writes the string into the response body. + WriteString(string) (int, error) + + // Returns true if the response body was already written. + Written() bool + + // Forces to write the http header (status code + headers). + WriteHeaderNow() + + // get the http.Pusher for server push + Pusher() http.Pusher +} + +func (w *responseWriter) Pusher() (pusher http.Pusher) { + if pusher, ok := w.ResponseWriter.(http.ResponseWriter).(http.Pusher); ok { + return pusher + } + return nil +}