Documentation
¶
Index ¶
- Constants
- Variables
- func CurrentZone() (string, int)
- func PrettyFormat(dur Duration) string
- func TimeToMySQL(val time.Time) string
- type ColorString
- func (cs *ColorString) AddAttr(index int) *ColorString
- func (cs *ColorString) Clear() *ColorString
- func (cs *ColorString) RemoveAttr(index int) *ColorString
- func (cs *ColorString) SetBG(col Colour) *ColorString
- func (cs *ColorString) SetBlink() *ColorString
- func (cs *ColorString) SetBold() *ColorString
- func (cs *ColorString) SetFG(col Colour) *ColorString
- func (cs *ColorString) SetFaint() *ColorString
- func (cs *ColorString) SetInverse() *ColorString
- func (cs *ColorString) SetItalic() *ColorString
- func (cs *ColorString) SetNormal() *ColorString
- func (cs *ColorString) SetStrikethru() *ColorString
- func (cs *ColorString) SetString(val string) *ColorString
- func (cs *ColorString) SetUnderline() *ColorString
- func (cs *ColorString) String() string
- type Colour
- type Datum
- type Duration
- func (obj Duration) Duration() time.Duration
- func (obj Duration) MarshalJSON() ([]byte, error)
- func (obj Duration) MarshalYAML() (any, error)
- func (obj *Duration) Set(str string) error
- func (obj *Duration) SetYAML(value any) error
- func (obj Duration) String() string
- func (obj Duration) Type() string
- func (obj *Duration) UnmarshalJSON(data []byte) error
- func (obj *Duration) UnmarshalYAML(value *yaml.Node) error
- func (obj Duration) Validate(minDuration, maxDuration time.Duration) error
- type Mailbox
- func (m *Mailbox) Empty() bool
- func (m *Mailbox) Full() bool
- func (m *Mailbox) Get() (Datum, bool)
- func (m *Mailbox) GetWithContext(ctx context.Context) (Datum, bool)
- func (m *Mailbox) Put(elem Datum) bool
- func (m *Mailbox) PutWithContext(ctx context.Context, elem Datum) bool
- func (m *Mailbox) Reset()
- func (m *Mailbox) TryGet() (Datum, bool)
- func (m *Mailbox) TryPut(item Datum) bool
- type Pair
- type Queue
- type RFC3339
- func (obj RFC3339) Add(d time.Duration) RFC3339
- func (obj RFC3339) After(t time.Time) bool
- func (obj RFC3339) Before(t time.Time) bool
- func (obj RFC3339) Equal(t time.Time) bool
- func (obj RFC3339) Format(format string) string
- func (obj RFC3339) IsDST() bool
- func (obj RFC3339) IsZero() bool
- func (obj RFC3339) MarshalJSON() ([]byte, error)
- func (obj RFC3339) MarshalYAML() (any, error)
- func (obj RFC3339) MySQL() string
- func (obj *RFC3339) Set(str string) error
- func (obj *RFC3339) SetYAML(value any) error
- func (obj RFC3339) String() string
- func (obj RFC3339) Sub(t time.Time) time.Duration
- func (obj RFC3339) Time() time.Time
- func (obj RFC3339) Type() string
- func (obj RFC3339) UTC() time.Time
- func (obj RFC3339) Unix() int64
- func (obj *RFC3339) UnmarshalJSON(data []byte) error
- func (obj *RFC3339) UnmarshalYAML(value *yaml.Node) error
Constants ¶
const ( Black Colour = '0' // Black colour -- ANSI. Red Colour = '1' // Red colour -- ANSI. Green Colour = '2' // Green colour -- ANSI. Yellow Colour = '3' // Yellow colour -- ANSI. Blue Colour = '4' // Blue colour -- ANSI. Magenta Colour = '5' // Magenta colour -- ANSI. Cyan Colour = '6' // Cyan colour -- ANSI. White Colour = '7' // White colour -- ANSI. Default Colour = '9' // Default colour -- ANSI. Normal int = 0 // Reset all attributes. Bold int = 1 // Bold -- VT100. Faint int = 2 // Faint, decreased intensity -- ECMA-48 2e. Italic int = 3 // Italicizsed -- ECMA-48 2e. Underline int = 4 // Underlined -- VT100. Blink int = 5 // Blinking -- VT100. Inverse int = 6 // Inverse video -- VT100. Strikethru int = 7 // Crossed-out characters -- ECMA-48 3e. )
CSI Pm [; Pm ...] m -- Character Attributes (SGR).
Variables ¶
var ( // Error condition that signals an invalid time duration of some kind. // // This error is usually wrapped around a descriptive message string. ErrInvalidDuration error = errors.Base("invalid time duration") // Error condition that signals that a duration is not a string value. // // This error is used by `Set` as well as JSON and YAML methods. ErrDurationNotString error = errors.Base("duration must be a string") // Error condition that signals that a duration is out of bounds. // // This is used by `Validate`. ErrOutOfBounds error = errors.Base("duration out of bounds") )
var ( // Error condition that signals an invalid RFC3339 timestamp of some // kind. // // This error is usually wrapped around a descriptive message string. ErrInvalidRFC3339 error = errors.Base("invalid RFC3339 timestamp") // Error condition that signals that an RFC3339 timestamp is not a // string format. // // This error is used by `Set` as well as JSON and YAML methods. ErrRFC3339NotString error = errors.Base("RFC3339 timestamp must be a string") )
Functions ¶
func CurrentZone ¶ added in v0.5.10
Return the current timezone for the host.
func PrettyFormat ¶ added in v0.5.10
Format a time duration in pretty format.
Example, a duration of 72 minutes becomes "1 hour(s), 12 minute(s)".
func TimeToMySQL ¶ added in v0.5.10
Convert a `time.Time` value to a MySQL timestamp for queries.
Types ¶
type ColorString ¶ added in v0.1.1
type ColorString struct {
// contains filtered or unexported fields
}
Colour string.
Generates a string that, with the right terminal type, display text using various character attributes.
To find out more, consult your nearest DEC VT340 programmer's manual or the latest ECMA-48 standard.
func NewColorString ¶ added in v0.5.10
func NewColorString() *ColorString
Make a new coloured string.
func NewColorStringWithColors ¶ added in v0.5.10
func NewColorStringWithColors( data string, foreg, backg Colour, ) *ColorString
Make a new coloured string with the given attributes.
func (*ColorString) AddAttr ¶ added in v0.5.10
func (cs *ColorString) AddAttr(index int) *ColorString
Add a specific attribute.
This ignores the "Normal" attribute. To clear attributes, use `SetNormal` or `Clear`.
func (*ColorString) Clear ¶ added in v0.5.10
func (cs *ColorString) Clear() *ColorString
Reset all attributes.
func (*ColorString) RemoveAttr ¶ added in v0.5.10
func (cs *ColorString) RemoveAttr(index int) *ColorString
Remove a specific attribute.
This ignores the "Normal" attribute. To clear attributes, use `SetNormal` or `Clear`.
func (*ColorString) SetBG ¶ added in v0.1.1
func (cs *ColorString) SetBG(col Colour) *ColorString
Set the background colour.
func (*ColorString) SetBlink ¶ added in v0.5.10
func (cs *ColorString) SetBlink() *ColorString
Set the blink attribute.
func (*ColorString) SetBold ¶ added in v0.5.10
func (cs *ColorString) SetBold() *ColorString
Set the bold attribute.
func (*ColorString) SetFG ¶ added in v0.1.1
func (cs *ColorString) SetFG(col Colour) *ColorString
Set the foreground colour.
func (*ColorString) SetFaint ¶ added in v0.5.10
func (cs *ColorString) SetFaint() *ColorString
Set the faint attribute.
func (*ColorString) SetInverse ¶ added in v0.5.10
func (cs *ColorString) SetInverse() *ColorString
Set the inverse video attribute.
func (*ColorString) SetItalic ¶ added in v0.5.10
func (cs *ColorString) SetItalic() *ColorString
Set the italic attribute.
func (*ColorString) SetNormal ¶ added in v0.5.10
func (cs *ColorString) SetNormal() *ColorString
Set the attribute to normal.
This removes all other attributes.
func (*ColorString) SetStrikethru ¶ added in v0.5.10
func (cs *ColorString) SetStrikethru() *ColorString
Set the strikethrough attribute.
func (*ColorString) SetString ¶ added in v0.1.1
func (cs *ColorString) SetString(val string) *ColorString
Set the string to display.
func (*ColorString) SetUnderline ¶ added in v0.5.10
func (cs *ColorString) SetUnderline() *ColorString
Set the underline attribute.
func (*ColorString) String ¶ added in v0.1.1
func (cs *ColorString) String() string
Convert to a string.
Warning: the resulting string will contain escape sequences for use with a compliant terminal or terminal emulator.
type Duration ¶ added in v0.5.9
Enhanced time duration type.
func NewFromDuration ¶ added in v0.5.10
func (Duration) MarshalJSON ¶ added in v0.5.9
JSON marshalling method.
func (Duration) MarshalYAML ¶ added in v0.5.9
YAML marshalling method.
func (*Duration) Set ¶ added in v0.5.9
Set the duration to that of the given string.
This method uses `time.ParseDuration`, so any string that `time` understands may be used.
If the string value fails parsing, then `ErrInvalidDuration` is returned.
func (*Duration) SetYAML ¶ added in v0.5.9
Set the duration value from a YAML value.
If the passed YAML value is not a string, then `ErrDurationNotString` is returned.
Will also return any error condition from the `Set` method.
func (*Duration) UnmarshalJSON ¶ added in v0.5.9
JSON unmarshalling method.
func (*Duration) UnmarshalYAML ¶ added in v0.5.9
YAML unmarshalling method.
type Mailbox ¶
type Mailbox struct {
// contains filtered or unexported fields
}
Mailbox structure.
This is a cheap implementation of a mailbox.
It uses two semaphores to control read and write access, and contains a single datum.
This is *not* a queue!
func NewMailbox ¶
func NewMailbox() *Mailbox
Create and return a new empty mailbox.
Note: this acquires the `readAvailable` semaphore.
func (*Mailbox) Get ¶
Get an element from the mailbox. Defaults to using a context with a deadline of 5 seconds.
func (*Mailbox) GetWithContext ¶
Get an element from the mailbox using the provided context.
It is recommended to use a context that has a timeout deadline.
func (*Mailbox) PutWithContext ¶ added in v1.0.5
Put an element into the mailbox using a context.
type Queue ¶
Queue structure.
This is a cheap implementation of a FIFO queue.
func NewBoundedQueue ¶
Create a queue that is bounded to a specific size.
type RFC3339 ¶ added in v0.5.10
RFC 3339 time type.
func Parse ¶ added in v0.5.10
Parse the given string for an RFC3339 timestamp.
If the timestamp is not a valid RFC3339 timestamp, then `ErrInvalidRFC3339` is returned.
func RFC3339FromUnix ¶ added in v1.0.5
Convert a Unix timestamp to an RFC3339 timestamp.
func (RFC3339) Add ¶ added in v0.5.10
Add a `time.Duration` value to the timestamp, returning a new timestamp.
func (RFC3339) IsDST ¶ added in v0.5.10
Does the timestamp correspond to a time where DST is in effect?
func (RFC3339) MarshalJSON ¶ added in v0.5.10
JSON marshalling method.
func (RFC3339) MarshalYAML ¶ added in v0.5.10
YAML marshalling method.
func (*RFC3339) Set ¶ added in v0.5.10
Set the RFC3339 timestamp to that of the given string.
If the string value fails to parse, then `ErrInvalidRFC3339` is returned.
func (*RFC3339) SetYAML ¶ added in v0.5.10
Set the RFC3339 value from a YAML value.
If the passed YAML value is not a string, then `ErrRFC3339NotString` is returned.
Will also return any error condition from the `Set` method.
func (RFC3339) Sub ¶ added in v0.5.10
Subtract a `time.Time` value from the timestamp, returning a `time.Duration`.
func (RFC3339) UTC ¶ added in v0.5.10
Return the UTC time for the timestamp.
RFC3339 timestamps are always UTC internally, so `UTC` is provided as a courtesy.
func (*RFC3339) UnmarshalJSON ¶ added in v0.5.10
JSON unmarshalling method.