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 BestNamedCertificate(c *tls.Config, clientHello *tls.ClientHelloInfo) (*tls.Certificate, bool)
- func CleanURLPath(p string) string
- func CopyExact(dest interface{}, src interface{})
- func Fatal(msg interface{})
- func FileInfoAccessTime(fi os.FileInfo) time.Time
- func FilePathExists(p string) bool
- func GetTestName() string
- func IsAddrInUse(err error) bool
- func IsZeroValue[T comparable](i T) bool
- func JitterDuration(average, plusMinus time.Duration) (ret time.Duration)
- func KebabCase(s string) string
- func LimitLen(b []byte, max ...interface{}) []bytedeprecated
- func LoadCertificateDir(dir string) (certs []tls.Certificate, err error)
- func Max(_less interface{}, vals ...interface{}) interface{}deprecated
- func MaxInt(first int64, rest ...interface{}) int64deprecated
- func MinInt(first interface{}, rest ...interface{}) int64deprecated
- func MonotonicSince(since MonotonicTime) (ret time.Duration)
- func NewSelfSignedCertificate() (cert tls.Certificate, err error)
- func ParseHostPort(hostport string) (host string, port int, err error)
- func PathSplitExt(p string) (ret struct{ ... })
- func PopScheme(u *url.URL) (scheme string, popped string)
- 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 ContextedReader
- type Encoding
- type Event
- type Flag
- type HostMaybePort
- type IdentityEncoding
- type IndentMap
- type IpPort
- type MonotonicTime
- type MultiLess
- type Operation
- type RWLocker
- type ReadContexter
- type ReadSeekContexter
- type RunLengthEncoder
- type SameLessFunc
- type SectionWriter
- type SingleFlight
- type SqliteTime
- type StatWriter
- type StatusResponseWriter
- type SynchronizedEvent
Examples ¶
Constants ¶
const MiB = 1 << 20
Variables ¶
var ZeroReader zeroReader
Functions ¶
func AddCondToFlags ¶
Adds the sync.Cond to all the given Flag's.
func BestNamedCertificate ¶
func BestNamedCertificate(c *tls.Config, clientHello *tls.ClientHelloInfo) (*tls.Certificate, bool)
Select the best named certificate per the usual behaviour if c.GetCertificate is nil, and c.NameToCertificate is not.
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 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 IsAddrInUse ¶
func IsZeroValue ¶
func IsZeroValue[T comparable](i T) bool
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 LoadCertificateDir ¶
func LoadCertificateDir(dir string) (certs []tls.Certificate, err error)
func Max
deprecated
func Max(_less interface{}, vals ...interface{}) interface{}
Deprecated: Use max builtin.
func MonotonicSince ¶
func MonotonicSince(since MonotonicTime) (ret time.Duration)
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 PopScheme ¶ added in v2.8.0
This exists because it's nontrivial to get everything after the scheme in a URL. You can't just use URL.Opaque because path handling kicks in if there's a slash after the scheme's colon.
func StoppedFuncTimer ¶
Returns a time.Timer that calls f. The timer is initially stopped.
func StringTruth ¶
func URLJoinSubPath ¶
func WaitEvents ¶
func WriteStack ¶
Types ¶
type ContextedReader ¶
type ContextedReader struct { R ReadContexter Ctx context.Context }
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Events are boolean flags that provide a channel that's closed when true. This could go in the sync package, but that's more of a debug wrapper on the standard library sync.
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 IdentityEncoding ¶
type IdentityEncoding struct{}
An encoding that does nothing.
func (IdentityEncoding) DecodeString ¶
func (IdentityEncoding) DecodeString(s string) ([]byte, error)
func (IdentityEncoding) EncodeToString ¶
func (IdentityEncoding) EncodeToString(b []byte) string
type IndentMap ¶
func NewExpvarIndentMap ¶
type IpPort ¶
func IpPortFromNetAddr ¶
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 MultiLess ¶
type MultiLess struct {
// contains filtered or unexported fields
}
A helper for long chains of "less-than" comparisons, where later comparisons are only required if earlier ones haven't resolved the comparison.
func (*MultiLess) Compare ¶ added in v2.3.0
Next use a common comparison result, where < 0 is less and 0 is equal.
func (*MultiLess) Final ¶
Returns the result of the less-than comparison chains. Panics if the case was not resolved.
func (*MultiLess) Less ¶
True iff the left is less than the right. Will return false if they're equal, or unresolved. (Which is okay in certain circumstances.)
func (*MultiLess) Next ¶
func (me *MultiLess) Next(f SameLessFunc)
`f` is only evaluated if the result is not yet determined.
func (*MultiLess) NextBool ¶
Compare booleans, where the lesser is the true one, if the other is false.
func (*MultiLess) StrictNext ¶
Like Next, but the arguments are already evaluated.
type ReadContexter ¶
type ReadSeekContexter ¶
type ReadSeekContexter interface { io.ReadSeeker ReadContexter }
func NewSectionReadSeeker ¶
func NewSectionReadSeeker(base io.ReadSeeker, off, size int64) (ret ReadSeekContexter)
Returns a ReadSeeker on a section of another ReadSeeker.
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 ¶
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 SameLessFunc ¶
type SameLessFunc func() (same, less bool)
A function that returns equality, and less than. Used for lazily evaluating arguments.
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 SqliteTime ¶
func (*SqliteTime) Scan ¶
func (me *SqliteTime) Scan(src interface{}) error
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 Started time.Time TimeToFirstByte time.Duration // Time to first byte GotFirstByte bool WroteHeader Event Hijacked bool }
A http.ResponseWriter that tracks the status of the response. The status code, and number of bytes written for example.
func (*StatusResponseWriter) Hijack ¶
func (me *StatusResponseWriter) Hijack() (c net.Conn, b *bufio.ReadWriter, err error)
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_go118.go
- encoding.go
- event.go
- event_synchronized.go
- expvarIndentMap.go
- flag.go
- hostmaybeport.go
- hostport.go
- httpresponsestatus.go
- ioutil.go
- ipport.go
- jitter.go
- limitlen.go
- minmax.go
- monotonic.go
- multiless.go
- net.go
- openflags.go
- path.go
- reader_context.go
- rle.go
- section_read_seeker.go
- section_writer.go
- selfcert.go
- singleflight.go
- sqlite.go
- stack.go
- strbool.go
- strcase.go
- sync.go
- testing.go
- timer.go
- tls.go
- units.go
- url.go
- wait_event.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
|
|
container
|
|
Package pproffd is for detecting resource leaks due to unclosed handles.
|
Package pproffd is for detecting resource leaks due to unclosed handles. |
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. |