Documentation ¶
Overview ¶
Package missinggo contains miscellaneous helpers used in many of anacrolix' projects.
Index ¶
- Constants
- func AddrIP(addr net.Addr) net.IP
- func AddrPort(addr net.Addr) int
- func ConvertToSliceOfEmptyInterface(slice interface{}) (ret []interface{})
- func CopyExact(dest interface{}, src interface{})
- func CryHeard() bool
- func Dispatch(dest, source interface{}) bool
- func Fatal(msg interface{})
- func FileInfoAccessTime(fi os.FileInfo) time.Time
- func FilePathExists(p string) bool
- func GzipHTTPHandler(h http.Handler) http.Handler
- func HTTPQuotedString(s string) string
- func IsEmptyValue(v reflect.Value) bool
- func NewSelfSignedCertificate() (cert tls.Certificate, err error)
- func PathSplitExt(p string) (ret struct{ ... })
- func Unchomp(s string) string
- func WriteStack(w io.Writer, stack []uintptr)
- type HTTPBytesContentRange
- type HTTPBytesRange
- type HostMaybePort
- type HostPort
- type IndentMap
- type Inheriter
- type RWLocker
- type RunLengthEncoder
- type SingleFlight
- type StatWriter
- type StatusResponseWriter
- type Wolf
- type ZeroReader
Examples ¶
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func ConvertToSliceOfEmptyInterface ¶
func ConvertToSliceOfEmptyInterface(slice interface{}) (ret []interface{})
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 Dispatch ¶
func Dispatch(dest, source interface{}) bool
Obtains the desired value pointed to by dest, from source. If it's not found in source, it will walk source's inheritance values until either blocked by visibility, an implementation is found, or there are no further bases. TODO: If an implementation is obtained from a base class that contains some methods present on a derived class, this might break encapsulation. Maybe there should be a check to ensure this isn't possible.
func FileInfoAccessTime ¶
Extracts the access time from the FileInfo internals.
func FilePathExists ¶
func GzipHTTPHandler ¶
Gzips response body if the request says it'll allow it.
func HTTPQuotedString ¶
Performs quoted-string from http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html
func IsEmptyValue ¶
Returns whether the value represents the empty value for its type. Used for example to determine if complex types satisfy the common "omitempty" tag option for marshalling. Taken from http://stackoverflow.com/a/23555352/149482.
func NewSelfSignedCertificate ¶
func NewSelfSignedCertificate() (cert tls.Certificate, err error)
Creates a self-signed certificate in memory for use with tls.Config.
func PathSplitExt ¶
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 WriteStack ¶
Types ¶
type HTTPBytesContentRange ¶
type HTTPBytesContentRange struct {
First, Last, Length int64
}
func ParseHTTPBytesContentRange ¶
func ParseHTTPBytesContentRange(s string) (ret HTTPBytesContentRange, ok bool)
type HTTPBytesRange ¶
type HTTPBytesRange struct {
First, Last int64
}
func ParseHTTPBytesRange ¶
func ParseHTTPBytesRange(s string) (ret HTTPBytesRange, ok bool)
type HostMaybePort ¶
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 ¶
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.
type IndentMap ¶
func NewExpvarIndentMap ¶
type Inheriter ¶
type Inheriter interface { // Return the base-class object value. Base() interface{} // Return a pointer to an interface containing the methods retrievable // from the base. Visible() interface{} }
A sort-of implementation of single dispatch polymorphic inheritance.
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/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 StatWriter ¶
type StatWriter struct { Written int64 // contains filtered or unexported fields }
func NewStatWriter ¶
func NewStatWriter(w io.Writer) *StatWriter
type StatusResponseWriter ¶
type StatusResponseWriter struct { RW http.ResponseWriter Code int BytesWritten int64 // contains filtered or unexported fields }
A http.ResponseWriter that tracks the status of the response. The status code, and number of bytes written for example.
func (*StatusResponseWriter) Base ¶
func (me *StatusResponseWriter) Base() interface{}
func (*StatusResponseWriter) Header ¶
func (me *StatusResponseWriter) Header() http.Header
func (*StatusResponseWriter) Visible ¶
func (me *StatusResponseWriter) Visible() interface{}
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.
type ZeroReader ¶
type ZeroReader struct{}