rtconn

package module
v0.0.0-...-9b3216d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2021 License: Apache-2.0 Imports: 9 Imported by: 1

README

Go Report Card GoDoc

rtconn

golang package to create a net.Conn based on a POST request and a given http.RoundTripper

usage

Example of creating a net.Conn from a HTTP2 request

package main

import (
	"context"
	"fmt"
	"io"
	"time"

	"github.com/igolaizola/rtconn"
)

func main() {
	// Dial to http2.golang.org example server
	dialer := rtconn.Dialer{Timeout: 10 * time.Second}
	conn, err := dialer.Dial(context.Background(), "https://http2.golang.org/reqinfo", nil)
	if err != nil {
		panic(err)
	}

	// Print received data until EOF or error
	data := make([]byte, 1024)
	for {
		n, err := conn.Read(data)
		if err == io.EOF {
			break
		}
		if err != nil {
			panic(err)
		}
		fmt.Printf(string(data[:n]))
	}

	// Close connection
	if err := conn.Close(); err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialer

type Dialer struct {
	// Transport specifies the mechanism by which HTTP POST request is made.
	// If nil, http.DefaultTransport is used.
	Transport http.RoundTripper

	// Timeout specifies a time limit for dialing.
	// A Timeout of zero means no timeout.
	Timeout time.Duration
}

Dialer is a dialer based on a http.RoundTripper

func (*Dialer) Dial

func (d *Dialer) Dial(parent context.Context, addr string, header http.Header) (net.Conn, error)

Dial creates a net.Conn based on a POST request within the http.RoundTripper

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL