Skip to content

Commit 4b4df91

Browse files
johnpmayerhoisie
authored andcommitted
Removed ResponseWriter interface and responseWriter struct
1 parent 1148b5c commit 4b4df91

File tree

1 file changed

+4
-29
lines changed

1 file changed

+4
-29
lines changed

web.go

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ import (
2626
"time"
2727
)
2828

29-
type ResponseWriter interface {
30-
Header() http.Header
31-
WriteHeader(status int)
32-
Write(data []byte) (n int, err error)
33-
Close()
34-
}
35-
3629
// A Context object is created for every incoming HTTP request, and is
3730
// passed to handlers as an optional first argument. It provides information
3831
// about the request, including the http.Request object, the GET and POST params,
@@ -41,7 +34,7 @@ type Context struct {
4134
Request *http.Request
4235
Params map[string]string
4336
Server *Server
44-
ResponseWriter
37+
http.ResponseWriter
4538
}
4639

4740
// WriteString writes string data into the response object.
@@ -208,23 +201,6 @@ func (s *Server) addRoute(r string, method string, handler interface{}) {
208201
}
209202
}
210203

211-
type responseWriter struct {
212-
http.ResponseWriter
213-
}
214-
215-
// Close terminates the HTTP connection, and flushes all pending
216-
// response data.
217-
func (c *responseWriter) Close() {
218-
rwc, buf, _ := c.ResponseWriter.(http.Hijacker).Hijack()
219-
if buf != nil {
220-
buf.Flush()
221-
}
222-
223-
if rwc != nil {
224-
rwc.Close()
225-
}
226-
}
227-
228204
// ServeHTTP is the interface method for Go's http server package
229205
func (s *Server) ServeHTTP(c http.ResponseWriter, req *http.Request) {
230206
s.Process(c, req)
@@ -281,7 +257,7 @@ func requiresContext(handlerType reflect.Type) bool {
281257
}
282258

283259
// the main route handler in web.go
284-
func (s *Server) routeHandler(req *http.Request, w ResponseWriter) {
260+
func (s *Server) routeHandler(req *http.Request, w http.ResponseWriter) {
285261
requestPath := req.URL.Path
286262
ctx := Context{req, map[string]string{}, s, w}
287263

@@ -391,7 +367,7 @@ type ServerConfig struct {
391367
RecoverPanic bool
392368
}
393369

394-
// Server represents a web.go server.
370+
// Server represents a web.go server.
395371
type Server struct {
396372
Config *ServerConfig
397373
routes []route
@@ -421,8 +397,7 @@ func (s *Server) initServer() {
421397

422398
// Process invokes the routing system for server s
423399
func (s *Server) Process(c http.ResponseWriter, req *http.Request) {
424-
w := responseWriter{c}
425-
s.routeHandler(req, &w)
400+
s.routeHandler(req, c)
426401
}
427402

428403
// Run starts the web application and serves HTTP requests for s

0 commit comments

Comments
 (0)