Documentation ¶
Overview ¶
Package missinggo contains miscellaneous helpers used in many of anacrolix' projects.
Index ¶
- Constants
- Variables
- func AddrIP(addr net.Addr) net.IP
- func AddrPort(addr net.Addr) int
- func CastSlice(slicePtr interface{}, fromSlice interface{})
- 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 GetTestName() string
- func HTTPQuotedString(s string) string
- func IsEmptyValue(v reflect.Value) bool
- func JitterDuration(average, plusMinus time.Duration) (ret time.Duration)
- func LimitLen(b *[]byte, max interface{})
- func MonotonicSince(since MonotonicTime) (ret time.Duration)
- func NewSectionReadSeeker(base io.ReadSeeker, off, size int64) (ret io.ReadSeeker)
- func NewSelfSignedCertificate() (cert tls.Certificate, err error)
- func PathSplitExt(p string) (ret struct{ ... })
- func StringTruth(s string) (ret bool)
- func Unchomp(s string) string
- func WriteStack(w io.Writer, stack []uintptr)
- type ChanCond
- type Event
- type File
- type FileStore
- type HTTPBytesContentRange
- type HTTPBytesRange
- type HostMaybePort
- type IndentMap
- type Inheriter
- type MonotonicTime
- type RWLocker
- type RunLengthEncoder
- type SectionWriter
- type SingleFlight
- type StatWriter
- type StatusResponseWriter
- type Wolf
Examples ¶
Constants ¶
const MiB = 1 << 20
Variables ¶
var ZeroReader zeroReader
Functions ¶
func ConvertToSliceOfEmptyInterface ¶
func ConvertToSliceOfEmptyInterface(slice interface{}) (ret []interface{})
func CopyExact ¶
func CopyExact(dest interface{}, src interface{})
Copy elements from src to dst. Panics if the length of src and dst are different.
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 GetTestName ¶
func GetTestName() string
Returns the name of the test function from the call stack. See http://stackoverflow.com/q/35535635/149482 for another method.
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 JitterDuration ¶
Returns random duration in the range [average-plusMinus, average+plusMinus]. Negative plusMinus will likely panic. Be aware that if plusMinus >= average, you may get a zero or negative Duration. The distribution function is unspecified, in case I find a more appropriate one in the future.
func LimitLen ¶
func LimitLen(b *[]byte, max interface{})
Sets an upper bound on the len of b. max can be any type that will cast to int64.
func MonotonicSince ¶
func MonotonicSince(since MonotonicTime) (ret time.Duration)
func NewSectionReadSeeker ¶
func NewSectionReadSeeker(base io.ReadSeeker, off, size int64) (ret io.ReadSeeker)
Returns a ReadSeeker on a section of another ReadSeeker.
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 StringTruth ¶
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 ¶
type HostMaybePort struct { Host string // Just the host, with no port. Port int // The port if NoPort is false. NoPort bool // Whether a port is specified. Err error // The error returned from net.SplitHostPort. }
Represents a split host port.
func SplitHostMaybePort ¶
func SplitHostMaybePort(hostport string) HostMaybePort
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 (*HostMaybePort) String ¶
func (me *HostMaybePort) String() string
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 MonotonicTime ¶
type MonotonicTime struct {
// contains filtered or unexported fields
}
Monotonic time represents time since an arbitrary point in the past, where the concept of now is only ever moving in a positive direction.
func MonotonicNow ¶
func MonotonicNow() MonotonicTime
Consecutive calls always produce the same or greater time than previous calls.
func (MonotonicTime) Sub ¶
func (me MonotonicTime) Sub(other MonotonicTime) time.Duration
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 SectionWriter ¶
type SectionWriter struct {
// contains filtered or unexported fields
}
func NewSectionWriter ¶
func NewSectionWriter(w io.WriterAt, off, len int64) *SectionWriter
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)
Source Files ¶
- addr.go
- atime.go
- atime_atim.go
- castslice.go
- chancond.go
- copy.go
- croak.go
- doc.go
- empty_value.go
- event.go
- expvarIndentMap.go
- fs.go
- hostmaybeport.go
- http.go
- httpcontentrange.go
- httpresponsestatus.go
- inherit.go
- ioutil.go
- jitter.go
- limitlen.go
- monotonic.go
- openflags.go
- path.go
- rle.go
- section_read_seeker.go
- section_writer.go
- selfcert.go
- singleflight.go
- stack.go
- strbool.go
- sync.go
- testing.go
- timer.go
- units.go
- wolf.go
Directories ¶
Path | Synopsis |
---|---|
Package bitmap provides a []bool/bitmap implementation with standardized iteration.
|
Package bitmap provides a []bool/bitmap implementation with standardized iteration. |
cmd
|
|
Package prioritybitmap implements a set of integers ordered by attached priorities.
|
Package prioritybitmap implements a set of integers ordered by attached priorities. |