missinggo

package
Version: v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2015 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package missinggo contains miscellaneous helpers used in many of anacrolix' projects.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddrIP

func AddrIP(addr net.Addr) net.IP

func AddrPort

func AddrPort(addr net.Addr) int

Extracts the port as an integer from an address string.

func ConvertToSliceOfEmptyInterface

func ConvertToSliceOfEmptyInterface(slice interface{}) (ret []interface{})

func CopyExact

func CopyExact(dest interface{}, src interface{})

func CopyURL

func CopyURL(u *url.URL) (ret *url.URL)

Deep copies a URL.

func CryHeard

func CryHeard() bool

Calls CryHeard() on a Wolf that is unique to the callers program counter. i.e. every CryHeard() expression has its own Wolf.

func Fatal

func Fatal(msg interface{})

func FileInfoAccessTime

func FileInfoAccessTime(fi os.FileInfo) time.Time

Extracts the access time from the FileInfo internals.

func FilePathExists

func FilePathExists(p string) bool

func GzipHTTPHandler

func GzipHTTPHandler(h http.Handler) http.Handler

Gzips response body if the request says it'll allow it.

func PathSplitExt

func PathSplitExt(p string) (ret struct {
	Root, Ext string
})

Splits the pathname p into Root and Ext, such that Root+Ext==p.

Example
fmt.Printf("%q\n", PathSplitExt(".cshrc"))
fmt.Printf("%q\n", PathSplitExt("dir/a.ext"))
fmt.Printf("%q\n", PathSplitExt("dir/.rc"))
fmt.Printf("%q\n", PathSplitExt("home/.secret/file"))
Output:

{"" ".cshrc"}
{"dir/a" ".ext"}
{"dir/" ".rc"}
{"home/.secret/file" ""}

func RequestedURL

func RequestedURL(r *http.Request) (ret *url.URL)

Reconstructs the URL that would have produced the given Request. Request.URLs are not fully populated in http.Server handlers.

func Unchomp

func Unchomp(s string) string

Types

type HTTPBytesContentRange

type HTTPBytesContentRange struct {
	First, Last, Length int64
}

func ParseHTTPBytesContentRange

func ParseHTTPBytesContentRange(s string) (ret HTTPBytesContentRange, ok bool)

type HostMaybePort

type HostMaybePort struct {
	Host   string
	Port   int
	NoPort bool
}

func SplitHostPort

func SplitHostPort(hostport string) (ret HostMaybePort)

func (HostMaybePort) String

func (me HostMaybePort) String() string

type HostPort

type HostPort struct {
	Host string // Just the host, with no port.
	Port string // May be empty if no port was given.
	Err  error  // The error returned from net.SplitHostPort.
}

func ParseHostPort

func ParseHostPort(hostPort string) (ret HostPort)

Parse a "hostport" string, a concept that floats around the stdlib a lot and is painful to work with. If no port is present, what's usually present is just the host.

func (*HostPort) Join

func (me *HostPort) Join() string

type IndentMap

type IndentMap struct {
	expvar.Map
}

func NewExpvarIndentMap

func NewExpvarIndentMap(name string) *IndentMap

func (*IndentMap) String

func (v *IndentMap) String() string

type RWLocker

type RWLocker interface {
	sync.Locker
	RLock()
	RUnlock()
}

type ReaderFromStatusResponseWriter

type ReaderFromStatusResponseWriter struct {
	StatusResponseWriter
	io.ReaderFrom
}

type RunLengthEncoder

type RunLengthEncoder interface {
	// Add a series of identical elements to the stream.
	Append(element interface{}, count uint64)
	// Emit the current element and its count if non-zero without waiting for
	// the element to change.
	Flush()
}

A RunLengthEncoder counts successive duplicate elements and emits the element and the run length when the element changes or the encoder is flushed.

func NewRunLengthEncoder

func NewRunLengthEncoder(eachRun func(element interface{}, count uint64)) RunLengthEncoder

Creates a new RunLengthEncoder. eachRun is called when an element and its count is emitted, per the RunLengthEncoder interface.

Example
package main

import (
	"fmt"

	"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/anacrolix/missinggo"
)

func main() {
	var s string
	rle := missinggo.NewRunLengthEncoder(func(e interface{}, count uint64) {
		s += fmt.Sprintf("%d%c", count, e)
	})
	for _, e := range "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW" {
		rle.Append(e, 1)
	}
	rle.Flush()
	fmt.Println(s)
}
Output:

12W1B12W3B24W1B14W

type SingleFlight

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

func (*SingleFlight) Lock

func (me *SingleFlight) Lock(id string)

func (*SingleFlight) Unlock

func (me *SingleFlight) Unlock(id string)

type StatusResponseWriter

type StatusResponseWriter struct {
	RW           http.ResponseWriter
	Code         int
	BytesWritten int64
}

A http.ResponseWriter that tracks the status of the response. The status code, and number of bytes written for example.

func (*StatusResponseWriter) CloseNotify

func (me *StatusResponseWriter) CloseNotify() <-chan bool

func (*StatusResponseWriter) Flush

func (me *StatusResponseWriter) Flush()

func (*StatusResponseWriter) Header

func (me *StatusResponseWriter) Header() http.Header

func (*StatusResponseWriter) Hijack

func (me *StatusResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (*StatusResponseWriter) Write

func (me *StatusResponseWriter) Write(b []byte) (n int, err error)

func (*StatusResponseWriter) WriteHeader

func (me *StatusResponseWriter) WriteHeader(code int)

type Wolf

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

A Wolf represents some event that becomes less and less interesting as it occurs. Call CryHeard to see if we should pay attention this time.

func (*Wolf) CryHeard

func (me *Wolf) CryHeard() bool

Returns true less and less often. Convenient for exponentially decreasing the amount of noise due to errors.

Directories

Path Synopsis
cmd
nop

Jump to

Keyboard shortcuts

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