Documentation ¶
Index ¶
- Constants
- Variables
- func Chomp(s string) string
- func CopyFile(src, dst string) error
- func Date(y, m, d int) time.Time
- func ExpandTilde(path string) string
- func Fexists(path string) (bool, error)
- func Fibonacci(n int) int64
- func FileSize(path string) (int64, error)
- func FmtBytes(bytes int64) string
- func GetHomeDirectory() string
- func IntRange(n int) []int
- func IsDir(path string) (bool, error)
- func Max[T Number](x, y T) T
- func Min[T Number](x, y T) T
- func Mtime(path string) (time.Time, error)
- func ParseURL(s string) *url.URL
- func RandomFilename() string
- func SplitOnWhitespace(s string) []string
- func StringSlice(arr []fmt.Stringer) []string
- func Trace()
- func TraceInfo() string
- type DateCounter
- type ID
- type Message
- type MessageBuffer
- type Number
- type Semaphore
Constants ¶
const TimestampFormat = "2006-01-02 15:04:05"
TimestampFormat is a commonly used format time values
Variables ¶
var ErrInvalidValue error = errors.New("invalid value")
ErrInvalidValue Indicates that some value is invalid.
var ErrNotImplemented error = errors.New("not implemented") // nolint: golint
ErrNotImplemented Indicates that some functionality is not implemented, yet.
Functions ¶
func CopyFile ¶
CopyFile copies the file at src to dst. It copies only the content, not metadata liker ownership, access right, etc.
In case of an error, an incomplete or corrupt file at dst might remain.
func ExpandTilde ¶
ExpandTilde replaces a leading "~" in a path with the current user's home directory.
func FileSize ¶
FileSize returns the size of the given file in bytes. If the file does not exist, it returns an error
func FmtBytes ¶
FmtBytes formats a number of bytes into a human-readable string, i.e. 1536 becomes "1.5 KB".
func GetHomeDirectory ¶
func GetHomeDirectory() string
GetHomeDirectory determines the user's home directory. The reason this is even a thing is that Unix-like systems store this path in the environment variable "HOME", whereas Windows uses the environment variable "USERPROFILE", Hence this function.
func IntRange ¶
IntRange returns a slice of integers in the range of [0,n) If that sounds primitive, that is because it *is* primitive -- languages like Perl or Ruby offer language primitives for this kind of feature. But Go likes to keep it simple, so here we go.
func IsDir ¶
IsDir checks if the given path exists and is a Directory. If the given path does not exists, it returns false, nil
func Mtime ¶
Mtime returns the mtime stamp of the given file. If the path does not exist, it returns an error
func ParseURL ¶
ParseURL parses a string containing (hopefully) a URL. Returns the url.URL pointer if successful, panics otherwise. The point is to be able to use this function to initialize "global" variables.
func RandomFilename ¶
func RandomFilename() string
RandommFilename generates filename that is randomized file name that should be random enough to avoid collisions.
CAVEAT: The randomness in these filenames is intended to avoid naming collisions by *accident*. They do *not* offer any kind of protection against a malicious adversary. Needless to say, they are also totally useless for anything that even /remotely/ anything to do with cryptography.
func SplitOnWhitespace ¶
SplitOnWhitespace splits a string on whitespace and returns a slice of the resulting substrings.
func StringSlice ¶
StringSlice takes a slice of Stringers (i.e. objects that implement the String() method), creates a slice of strings of the same size as the input, then calls String() on each member of the input slice and stores the result in the output slice which it returns at the end.
func Trace ¶
func Trace()
Trace emits info about the CALLING function I found this code on StackOverflow, so the copyright situation is a bit hazy. Then again, if you didn't want people to use your code like I do here, you'd probably not post it in StackOverflow. Ergo I consider this public domain code, since I am now also unable to find the thread where I saw this code. My point is that I did not come up with this myself but I use it happily.
PS: I should readlly give this function a do-over so that it returns
the data it obtains, rather than writing it to Stdout.
Types ¶
type DateCounter ¶
type DateCounter struct {
// contains filtered or unexported fields
}
DateCounter is a counter that returns consecutive days.
func NewDateCounter ¶
func NewDateCounter(y, m, d int) *DateCounter
NewDateCounter creates a new date counter that starts counting at the given date.
func (*DateCounter) Next ¶
func (dc *DateCounter) Next() time.Time
Next returns the next date, starting with the date given as the starting date, then adding one day per consecutive call.
type ID ¶
type ID int64
ID is an identifier that is unique within a given context.
const INVALID_ID ID = -1
INVALID_ID is an ID that does not equal any valid ID.
type Message ¶
Message is a ... message that can sent and received via the MessageBuffer.
func (*Message) StampString ¶
StampString returns the Message's timestamp as a string.
type MessageBuffer ¶
type MessageBuffer struct {
// contains filtered or unexported fields
}
MessageBuffer is a queue-like structure.
func CreateMessageBuffer ¶
func CreateMessageBuffer() *MessageBuffer
CreateMessageBuffer creates a MessageBuffer.
func (*MessageBuffer) AddMessage ¶
func (b *MessageBuffer) AddMessage(msg string)
AddMessage adds a message to the Buffer
func (*MessageBuffer) Count ¶
func (b *MessageBuffer) Count() int
Count returns the number of messages currently queued in the buffer.
func (*MessageBuffer) Empty ¶
func (b *MessageBuffer) Empty() bool
Empty returns true if the queue is currently empty.
func (*MessageBuffer) GetAllMessages ¶
func (b *MessageBuffer) GetAllMessages() []Message
GetAllMessages retrieves all Messages that are currently in the queue.
func (*MessageBuffer) GetOneMessage ¶
func (b *MessageBuffer) GetOneMessage() *Message
GetOneMessage retrieves a single message from the MessageBuffer.
func (*MessageBuffer) Running ¶
func (b *MessageBuffer) Running() bool
Running returns true if the MessgeBuffer is active.
func (*MessageBuffer) Stop ¶
func (b *MessageBuffer) Stop()
Stop tells the message buffer to cease activity.
type Number ¶
type Number interface { int | uint | int8 | uint8 | int16 | uint16 | int32 | uint32 | int64 | uint64 | float32 | float64 }
Number is the sum type of all integer and floating point types that are strictly ordered.
type Semaphore ¶
type Semaphore struct {
// contains filtered or unexported fields
}
Semaphore implements a classic among synchronization facilities.
func NewSemaphore ¶
NewSemaphore creates, uh, a new semaphore with a maximum counter value of max.