Skip to content

Instantly share code, notes, and snippets.

@prakashpandey
Last active November 30, 2024 05:36
Show Gist options
  • Save prakashpandey/f8fe3e8f3d446cd3426ac67ac21172f7 to your computer and use it in GitHub Desktop.
Save prakashpandey/f8fe3e8f3d446cd3426ac67ac21172f7 to your computer and use it in GitHub Desktop.

Revisions

  1. Prakash revised this gist Jan 28, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion CustomResponseWriter.go
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ type CustomResponseWriter struct {
    header http.Header
    }

    func NewCustomResponseWriter() *customResponseWriter {
    func NewCustomResponseWriter() *CustomResponseWriter {
    return &CustomResponseWriter{
    header: http.Header{},
    }
  2. Prakash revised this gist Jan 28, 2019. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion CustomResponseWriter.go
    Original 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 := &CustomResponseWriter{}
    w := NewCustomResponseWriter()
    okFn(w, r)
    fmt.Println(w.statusCode)
    }
  3. Prakash revised this gist Jan 28, 2019. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions CustomResponseWriter.go
    Original file line number Diff line number Diff line change
    @@ -33,9 +33,7 @@ func main() {
    r := &http.Request{
    Method: http.MethodPost,
    }
    w := &CustomResponseWriter{
    statusCode: 100,
    }
    w := &CustomResponseWriter{}
    okFn(w, r)
    fmt.Println(w.statusCode)
    }
  4. Prakash revised this gist Jan 28, 2019. No changes.
  5. Prakash revised this gist Jan 28, 2019. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions CustomResponseWriter.go
    Original file line number Diff line number Diff line change
    @@ -5,23 +5,23 @@ import (
    "net/http"
    )

    type customResponseWriter struct {
    type CustomResponseWriter struct {
    body []byte
    statusCode int
    header http.Header
    }

    func (w *customResponseWriter) Header() http.Header {
    func (w *CustomResponseWriter) Header() http.Header {
    return w.header
    }

    func (w *customResponseWriter) Write(b []byte) (int, error) {
    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) {
    func (w *CustomResponseWriter) WriteHeader(statusCode int) {
    w.statusCode = statusCode
    }

    @@ -33,7 +33,7 @@ func main() {
    r := &http.Request{
    Method: http.MethodPost,
    }
    w := &customResponseWriter{
    w := &CustomResponseWriter{
    statusCode: 100,
    }
    okFn(w, r)
  6. Prakash created this gist Jan 28, 2019.
    41 changes: 41 additions & 0 deletions CustomResponseWriter.go
    Original 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)
    }