countconn

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2019 License: MIT Imports: 6 Imported by: 0

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"

	"github.com/cryptix/go/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"

	"github.com/cryptix/go/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