Documentation ¶
Overview ¶
Package missinggo contains miscellaneous helpers used in many of anacrolix' projects.
Index ¶
- Constants
- Variables
- func AddCondToFlags(cond *sync.Cond, flags ...*Flag)
- func AddrIP(addr net.Addr) net.IP
- func AddrPort(addr net.Addr) int
- func CleanURLPath(p string) string
- func CopyExact(dest interface{}, src interface{})
- func CryHeard() bool
- func Fatal(msg interface{})
- func FileInfoAccessTime(fi os.FileInfo) time.Time
- func FilePathExists(p string) bool
- func GetTestName() string
- func IsEmptyValue(v reflect.Value) bool
- func JitterDuration(average, plusMinus time.Duration) (ret time.Duration)
- func LimitLen(b *[]byte, max interface{})
- func LoadCertificateDir(dir string) (certs []tls.Certificate, err error)
- func Max(_less interface{}, vals ...interface{}) 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 ParseHostPort(hostport string) (host string, port int, err error)
- func PathSplitExt(p string) (ret struct{ ... })
- func StoppedFuncTimer(f func()) (t *time.Timer)
- func StringTruth(s string) (ret bool)
- func URLJoinSubPath(base, rel string) string
- func URLOpaquePath(u *url.URL) string
- func Unchomp(s string) string
- func WaitEvents(l sync.Locker, evs ...*Event)
- func WriteStack(w io.Writer, stack []uintptr)
- type ChanCond
- type Event
- type File
- type FileStore
- type Flag
- type HostMaybePort
- type IndentMap
- type MonotonicTime
- type Operation
- type RWLocker
- type RunLengthEncoder
- type SectionWriter
- type SingleFlight
- type StatWriter
- type StatusResponseWriter
- type SynchronizedEvent
- type Wolf
Examples ¶
Constants ¶
const MiB = 1 << 20
Variables ¶
var ZeroReader zeroReader
Functions ¶
func AddCondToFlags ¶
Adds the sync.Cond to all the given Flag's.
func CleanURLPath ¶
Cleans the (absolute) URL path, removing unnecessary . and .. elements. See "net/http".cleanPath.
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 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 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 LoadCertificateDir ¶
func LoadCertificateDir(dir string) (certs []tls.Certificate, err error)
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 StoppedFuncTimer ¶
Returns a time.Timer that calls f. The timer is initially stopped.
func StringTruth ¶
func URLJoinSubPath ¶
func WaitEvents ¶
func WriteStack ¶
Types ¶
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Events are boolean flags that provide a channel that's closed when true.
func (*Event) C ¶
func (me *Event) C() <-chan struct{}
Returns a chan that is closed when the event is true.
func (*Event) LockedChan ¶
type Flag ¶
Flag represents a boolean value, that signals sync.Cond's when it changes. It's not concurrent safe by intention.
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 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) Operation
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 { 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) Write ¶
func (me *StatusResponseWriter) Write(b []byte) (n int, err error)
func (*StatusResponseWriter) WriteHeader ¶
func (me *StatusResponseWriter) WriteHeader(code int)
type SynchronizedEvent ¶
type SynchronizedEvent struct {
// contains filtered or unexported fields
}
func (*SynchronizedEvent) C ¶
func (me *SynchronizedEvent) C() <-chan struct{}
func (*SynchronizedEvent) Clear ¶
func (me *SynchronizedEvent) Clear()
func (*SynchronizedEvent) Set ¶
func (me *SynchronizedEvent) Set()
Source Files ¶
- addr.go
- atime.go
- atime_atim.go
- certdir.go
- chancond.go
- copy.go
- croak.go
- doc.go
- empty_value.go
- event.go
- event_synchronized.go
- expvarIndentMap.go
- flag.go
- fs.go
- hostmaybeport.go
- hostport.go
- httpresponsestatus.go
- ioutil.go
- jitter.go
- limitlen.go
- max.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
- url.go
- wait_event.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. |
Package slices has several utilities for operating on slices given Go's lack of generic types.
|
Package slices has several utilities for operating on slices given Go's lack of generic types. |