Skip to content

Instantly share code, notes, and snippets.

@jamisonhyatt
Created February 9, 2018 09:27
Show Gist options
  • Select an option

  • Save jamisonhyatt/1e20d73a37f194d9b99a838be6cb8275 to your computer and use it in GitHub Desktop.

Select an option

Save jamisonhyatt/1e20d73a37f194d9b99a838be6cb8275 to your computer and use it in GitHub Desktop.

Revisions

  1. jamisonhyatt created this gist Feb 9, 2018.
    26 changes: 26 additions & 0 deletions gwmux.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    gwmux := runtime.NewServeMux(runtime.WithForwardResponseOption(forwardResponseOption))

    func forwardResponseOption(ctx context.Context, w http.ResponseWriter, p proto.Message) error {

    for k, v := range w.Header() {
    log.Printf("%s=%s\n", k, v)
    }

    md, ok := runtime.ServerMetadataFromContext(ctx)
    if !ok {
    log.Println("Unable to retrieve metadata from context")
    return fmt.Errorf("error parsing server metadata from context: %v", ok)
    }

    log.Printf("Receieved %v items in header metata data and %v items in trailer metadata\n",
    md.HeaderMD.Len(), md.TrailerMD.Len())

    for k, v := range md.HeaderMD {
    log.Printf("%s=%s\n", k, v)
    }

    for k, v := range md.TrailerMD {
    log.Printf("%s=%s\n", k, v)
    }
    return nil
    }