Documentation
¶
Overview ¶
Package watcher that handles file renames
Index ¶
- Constants
- Variables
- func Decode(value any, arg interface{}) error
- func DecodeAsBool(value any) bool
- func DecodeAsInt(value any) int
- func DecodeAsNumber(value any) float32
- func DecodeAsObject(value any, object interface{}) error
- func DecodeAsString(value any, maxlen int) string
- func FormatAge(dateStr string) (age string)
- func FormatDateTime(dateStr string, format ...string) string
- func FormatMSE(mse int64, short bool) string
- func FormatNowUTCMilli() string
- func FormatUTCMilli(t time.Time) string
- func MapKeys[K comparable, V any](mm map[K]V) []K
- func OrderedMapKeys[K constraints.Ordered, V any](mm map[K]V) []K
- func Substitute(s string, vars map[string]string) string
- func WatchFile(path string, handler func() error) (*fsnotify.Watcher, error)
Constants ¶
const ( COReset = "\033[0m" CORed = "\033[31m" COGreen = "\033[32m" COYellow = "\033[33m" COBlue = "\033[34m" COPurple = "\033[35m" COCyan = "\033[36m" COGray = "\033[37m" COWhite = "\033[97m" )
Console ASCII commands to control colors See also: https://www.codequoi.com/en/coloring-terminal-text-tput-and-ansi-escape-sequences/
const ( CBBlack = "\033[40m" CBRed = "\033[41m" CBGreen = "\033[42m" CBYellow = "\033[43m" CBBlue = "\033[44m" CBGray = "\033[47m" CBWhite = "\033[41m" )
const ( WrapOff = "\033[?7l" WrapOn = "\033[?7h" )
Variables ¶
var MilliTimeFormat = "2006-01-02 15:04:05.000 MST" // millisecond
var VerboseTimeFormat = time.RFC1123 // full date-time
var WeekTimeFormat = "Mon 02, 15:04:05 MST" // for the last 7 days
each of these formats can be updated
var YearTimeFormat = "2006-01-02, 15:04:05 MST" // full date-time
Functions ¶
func Decode ¶
Decode converts the any-type to the given interface type. If the output type is a native type then also consider using one of the DecodeAs... methods as these are likely more performant. This returns an error if conversion fails.
func DecodeAsBool ¶
DecodeAsBool converts the value to a boolean. If value is already a boolean then it is returned as-is.
func DecodeAsInt ¶
DecodeAsInt converts the value to an integer. This accepts int, int64, *int, bool, uint, float32/64 If value is already an integer then it is returned as-is. If value > int (eg int64) then the result is unpredicable
func DecodeAsNumber ¶
DecodeAsNumber converts the value to a float32 number. If value is already a float32 then it is returned as-is.
func DecodeAsObject ¶
DecodeAsObject converts the value to an object. If the object is of the same type then it is copied otherwise a json marshal/unmarshal is attempted for a deep conversion.
func DecodeAsString ¶
DecodeAsString converts the value to a string if value is already a string then it is returned as-is if maxlen is provided then limit the resulting length and add ... if exceeded. Use 0 for all.
func FormatAge ¶
FormatAge converts the given time to the current short age format h m s ago
If time is less than an hour: minutes seconds ago If time is less than a day: hours minutes ago If time is less than a month: days hours minutes ago If time is more than a month: days hours ago
func FormatDateTime ¶
FormatDateTime format an iso date/time string into a human readable format value is an iso timestamp Format:
"" default is the year time format: YYYY-MM-DD, HH:MM:SS TZ "S" is the shortest possible format depending on agent "V" is the verbose format "AGE" is the age format like "5m 30s ago"
format is default RFC822, or use "S" for a short format "weekday, time" if less than a week old
func FormatMSE ¶
FormatMSE returns a human-readable string into local time in millisec since epoc
These are in timezone: time.Now().Zone() The short format is: StampMilli: Jan _2 15:04:05.000 (local time) The long format is: YYYY-MM-DD HH:MM:SS TZ
func FormatNowUTCMilli ¶
func FormatNowUTCMilli() string
FormatNowUTCMilli returns the current time in UTC milliseconds
func FormatUTCMilli ¶
FormatUTCMilli returns the given time in UTC with milliseconds, yyyy-mm-ddThh:mm:ss.000Z
func OrderedMapKeys ¶
func OrderedMapKeys[K constraints.Ordered, V any](mm map[K]V) []K
OrderedMapKeys returns an ordered slice of keys
func Substitute ¶
Substitute substitutes the variables in a string Variables are define with curly brackets, eg: "this is a {variableName}"
func WatchFile ¶
WatchFile is a resilient file watcher that handles file renames Special features:
- This debounces multiple quick changes before invoking the callback
- After the callback, resubscribe to the file to handle file renames that change the file inode path to watch handler to invoke on change
This returns the fsnotify watcher. Remove it when done.
Types ¶
This section is empty.