countconn

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2021 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapConn

func WrapConn(logger log.Logger, c net.Conn) net.Conn

Types

type Conn

type Conn struct {
	*Reader
	*Writer
	// contains filtered or unexported fields
}

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader counts the bytes read through it.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader makes a new Reader that counts the bytes read through it.

Example
package main

import (
	"fmt"
	"io"
	"os"
	"strings"

	"go.mindeco.de/logging/countconn"
)

func main() {
	r := strings.NewReader("hello, world\n")
	rc := countconn.NewReader(r)

	n, err := io.Copy(os.Stdout, rc)
	fmt.Println(err)
	fmt.Println(n)
	fmt.Println(rc.N())

}
Output:

hello, world
<nil>
13
13

func (*Reader) N

func (r *Reader) N() int64

N gets the number of bytes that have been read so far.

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer counts the bytes read through it.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter makes a new Writer that counts the bytes read through it.

Example
package main

import (
	"bytes"
	"fmt"
	"io"
	"strings"

	"go.mindeco.de/logging/countconn"
)

func main() {
	var w bytes.Buffer
	wc := countconn.NewWriter(&w)

	n, err := io.Copy(wc, strings.NewReader("hello, world\n"))
	fmt.Print(w.String())
	fmt.Println(err)
	fmt.Println(n)
	fmt.Println(wc.N())

}
Output:

hello, world
<nil>
13
13

func (*Writer) N

func (w *Writer) N() int64

N gets the number of bytes that have been written so far.

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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