github.com/newrelic/go-agent@v3.26.0+incompatible/internal_response_writer.go (about)

     1  // Copyright 2020 New Relic Corporation. All rights reserved.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package newrelic
     5  
     6  import (
     7  	"bufio"
     8  	"io"
     9  	"net"
    10  	"net/http"
    11  
    12  	"github.com/newrelic/go-agent/internal"
    13  )
    14  
    15  func (thd *thread) CloseNotify() <-chan bool {
    16  	return thd.txn.getWriter().(http.CloseNotifier).CloseNotify()
    17  }
    18  func (thd *thread) Flush() {
    19  	thd.txn.getWriter().(http.Flusher).Flush()
    20  }
    21  func (thd *thread) Hijack() (net.Conn, *bufio.ReadWriter, error) {
    22  	return thd.txn.getWriter().(http.Hijacker).Hijack()
    23  }
    24  func (thd *thread) ReadFrom(r io.Reader) (int64, error) {
    25  	return thd.txn.getWriter().(io.ReaderFrom).ReadFrom(r)
    26  }
    27  
    28  type threadWithExtras interface {
    29  	Transaction
    30  	internal.AddAgentAttributer
    31  	internal.AddAgentSpanAttributer
    32  }
    33  
    34  func upgradeTxn(thd *thread) Transaction {
    35  	// Note that thd.txn.getWriter() is not used here.  The transaction is
    36  	// locked (or under construction) when this function is used.
    37  
    38  	// GENERATED CODE DO NOT MODIFY
    39  	// This code generated by internal/tools/interface-wrapping
    40  	var (
    41  		i0 int32 = 1 << 0
    42  		i1 int32 = 1 << 1
    43  		i2 int32 = 1 << 2
    44  		i3 int32 = 1 << 3
    45  	)
    46  	var interfaceSet int32
    47  	if _, ok := thd.txn.writer.(http.CloseNotifier); ok {
    48  		interfaceSet |= i0
    49  	}
    50  	if _, ok := thd.txn.writer.(http.Flusher); ok {
    51  		interfaceSet |= i1
    52  	}
    53  	if _, ok := thd.txn.writer.(http.Hijacker); ok {
    54  		interfaceSet |= i2
    55  	}
    56  	if _, ok := thd.txn.writer.(io.ReaderFrom); ok {
    57  		interfaceSet |= i3
    58  	}
    59  	switch interfaceSet {
    60  	default: // No optional interfaces implemented
    61  		return struct {
    62  			threadWithExtras
    63  		}{thd}
    64  	case i0:
    65  		return struct {
    66  			threadWithExtras
    67  			http.CloseNotifier
    68  		}{thd, thd}
    69  	case i1:
    70  		return struct {
    71  			threadWithExtras
    72  			http.Flusher
    73  		}{thd, thd}
    74  	case i0 | i1:
    75  		return struct {
    76  			threadWithExtras
    77  			http.CloseNotifier
    78  			http.Flusher
    79  		}{thd, thd, thd}
    80  	case i2:
    81  		return struct {
    82  			threadWithExtras
    83  			http.Hijacker
    84  		}{thd, thd}
    85  	case i0 | i2:
    86  		return struct {
    87  			threadWithExtras
    88  			http.CloseNotifier
    89  			http.Hijacker
    90  		}{thd, thd, thd}
    91  	case i1 | i2:
    92  		return struct {
    93  			threadWithExtras
    94  			http.Flusher
    95  			http.Hijacker
    96  		}{thd, thd, thd}
    97  	case i0 | i1 | i2:
    98  		return struct {
    99  			threadWithExtras
   100  			http.CloseNotifier
   101  			http.Flusher
   102  			http.Hijacker
   103  		}{thd, thd, thd, thd}
   104  	case i3:
   105  		return struct {
   106  			threadWithExtras
   107  			io.ReaderFrom
   108  		}{thd, thd}
   109  	case i0 | i3:
   110  		return struct {
   111  			threadWithExtras
   112  			http.CloseNotifier
   113  			io.ReaderFrom
   114  		}{thd, thd, thd}
   115  	case i1 | i3:
   116  		return struct {
   117  			threadWithExtras
   118  			http.Flusher
   119  			io.ReaderFrom
   120  		}{thd, thd, thd}
   121  	case i0 | i1 | i3:
   122  		return struct {
   123  			threadWithExtras
   124  			http.CloseNotifier
   125  			http.Flusher
   126  			io.ReaderFrom
   127  		}{thd, thd, thd, thd}
   128  	case i2 | i3:
   129  		return struct {
   130  			threadWithExtras
   131  			http.Hijacker
   132  			io.ReaderFrom
   133  		}{thd, thd, thd}
   134  	case i0 | i2 | i3:
   135  		return struct {
   136  			threadWithExtras
   137  			http.CloseNotifier
   138  			http.Hijacker
   139  			io.ReaderFrom
   140  		}{thd, thd, thd, thd}
   141  	case i1 | i2 | i3:
   142  		return struct {
   143  			threadWithExtras
   144  			http.Flusher
   145  			http.Hijacker
   146  			io.ReaderFrom
   147  		}{thd, thd, thd, thd}
   148  	case i0 | i1 | i2 | i3:
   149  		return struct {
   150  			threadWithExtras
   151  			http.CloseNotifier
   152  			http.Flusher
   153  			http.Hijacker
   154  			io.ReaderFrom
   155  		}{thd, thd, thd, thd, thd}
   156  	}
   157  }