Last active
November 30, 2024 05:36
-
-
Save prakashpandey/f8fe3e8f3d446cd3426ac67ac21172f7 to your computer and use it in GitHub Desktop.
Revisions
-
Prakash revised this gist
Jan 28, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ type CustomResponseWriter struct { header http.Header } func NewCustomResponseWriter() *CustomResponseWriter { return &CustomResponseWriter{ header: http.Header{}, } -
Prakash revised this gist
Jan 28, 2019 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,6 +11,12 @@ type CustomResponseWriter struct { header http.Header } func NewCustomResponseWriter() *customResponseWriter { return &CustomResponseWriter{ header: http.Header{}, } } func (w *CustomResponseWriter) Header() http.Header { return w.header } @@ -33,7 +39,7 @@ func main() { r := &http.Request{ Method: http.MethodPost, } w := NewCustomResponseWriter() okFn(w, r) fmt.Println(w.statusCode) } -
Prakash revised this gist
Jan 28, 2019 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,9 +33,7 @@ func main() { r := &http.Request{ Method: http.MethodPost, } w := &CustomResponseWriter{} okFn(w, r) fmt.Println(w.statusCode) } -
Prakash revised this gist
Jan 28, 2019 . No changes.There are no files selected for viewing
-
Prakash revised this gist
Jan 28, 2019 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,23 +5,23 @@ import ( "net/http" ) type CustomResponseWriter struct { body []byte statusCode int header http.Header } func (w *CustomResponseWriter) Header() http.Header { return w.header } func (w *CustomResponseWriter) Write(b []byte) (int, error) { w.body = b // implement it as per your requirement return 0, nil } func (w *CustomResponseWriter) WriteHeader(statusCode int) { w.statusCode = statusCode } @@ -33,7 +33,7 @@ func main() { r := &http.Request{ Method: http.MethodPost, } w := &CustomResponseWriter{ statusCode: 100, } okFn(w, r) -
Prakash created this gist
Jan 28, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ package main import ( "fmt" "net/http" ) type customResponseWriter struct { body []byte statusCode int header http.Header } func (w *customResponseWriter) Header() http.Header { return w.header } func (w *customResponseWriter) Write(b []byte) (int, error) { w.body = b // implement it as per your requirement return 0, nil } func (w *customResponseWriter) WriteHeader(statusCode int) { w.statusCode = statusCode } var okFn = func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) } func main() { r := &http.Request{ Method: http.MethodPost, } w := &customResponseWriter{ statusCode: 100, } okFn(w, r) fmt.Println(w.statusCode) }