Documentation
¶
Overview ¶
Package cog is a collection of utilities that I tend to use across many of my projects. Rather than reinventing the cog everywhere, I've just consolidated them all here.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Errors ¶
type Errors struct {
// contains filtered or unexported fields
}
Errors holds a list of errors that can be combined into a single, line- delimited error message
Example ¶
es := Errors{} // Nothing added es.Add(nil) es.Addf(nil, "something describing the error: %d", 123) fmt.Println("no errors:", es.Error()) // Errors logged es.Add(fmt.Errorf("some error")) es.Addf(fmt.Errorf("another error"), "something describing the error: %d", 123) fmt.Println("errors:", es.Error())
Output: no errors: <nil> errors: some error something describing the error: 123: another error
func (*Errors) Addf ¶
Addf is like Add, but prefixes the error with the given format and args. If err==nil, this does nothing.
func (*Errors) Error ¶
Error combines all previous errors into a single error, or returns nil if there were no errors.
type Exit ¶
type Exit struct { *GExit // contains filtered or unexported fields }
Exit is useful for terminating a group of goroutines that run in a for{select{}}. Be sure to `Exit.Add(n)` before starting goroutines, and `defer Exit.Done()` in the goroutine.
Example ¶
e := NewExit() run := func(i int) { e.Add(1) fmt.Println(i, "started") go func() { defer e.Done() defer fmt.Println("exited") for { select { case <-e.C: return } } }() } for i := 0; i < 10; i++ { run(i) } // Wait for all goroutines to exit e.Exit()
Output: 0 started 1 started 2 started 3 started 4 started 5 started 6 started 7 started 8 started 9 started exited exited exited exited exited exited exited exited exited exited
type Exiter ¶
type Exiter interface {
Exit()
}
Exiter is anything that can cleanup after itself at any arbitrary point in time.
type GExit ¶
GExit (short for "goroutine exit") is what should be passed to things that need to know when to exit but that should not be able to trigger an exit.
Directories
¶
Path | Synopsis |
---|---|
Package bytec implements some bytes utilities.
|
Package bytec implements some bytes utilities. |
Package cfs implements some extra filesystem utilities
|
Package cfs implements some extra filesystem utilities |
Package check provides dead-simple assertions and utilities for testing.
|
Package check provides dead-simple assertions and utilities for testing. |
chlog
Package chlog provides clog-based logging for testing Usage is really simple: import "github.com/iheartradio/cog/check/chlog" func TestStuff(t *testing.T) { log := chlog.New(t) }
|
Package chlog provides clog-based logging for testing Usage is really simple: import "github.com/iheartradio/cog/check/chlog" func TestStuff(t *testing.T) { log := chlog.New(t) } |
Package cio implements extra io utils
|
Package cio implements extra io utils |
eio
Package eio implements extensible, async io backends.
|
Package eio implements extensible, async io backends. |
eio/kafka
Package kafka implements an eio producer and consumer for kafka.
|
Package kafka implements an eio producer and consumer for kafka. |
Package clog implements a python-like, module-based logger with a variety of backends and formats.
|
Package clog implements a python-like, module-based logger with a variety of backends and formats. |
cmd
|
|
Package cnet provides more network utils, including sockets made from channels.
|
Package cnet provides more network utils, including sockets made from channels. |
Package cort implements extra sort helpers.
|
Package cort implements extra sort helpers. |
Package ctime implements extra time utilities.
|
Package ctime implements extra time utilities. |
Package cync implements some sync extras "cync" is pronounced "sync".
|
Package cync implements some sync extras "cync" is pronounced "sync". |
encoding
|
|
capnp
Package capnp implements some stupid stuff for capnproto
|
Package capnp implements some stupid stuff for capnproto |
path
Package path provides Marshaling and Unmarshaling for [ ]byte-encoded paths.
|
Package path provides Marshaling and Unmarshaling for [ ]byte-encoded paths. |
Package node provides information about the local node
|
Package node provides information about the local node |
Package stack provides some utilities for dealing with the call stack.
|
Package stack provides some utilities for dealing with the call stack. |
Package statc implements runtime process stats and status reporting.
|
Package statc implements runtime process stats and status reporting. |
Package stringc implements some strings extras "stringc" is pronounced "strings".
|
Package stringc implements some strings extras "stringc" is pronounced "strings". |
Package unsafec makes unsafe even more unsafe.
|
Package unsafec makes unsafe even more unsafe. |