Skip to content
/ guts Public

Go utility library

License

MIT, Apache-2.0 licenses found

Licenses found

MIT
LICENSE
Apache-2.0
LICENSE_APACHE_2.0
Notifications You must be signed in to change notification settings

daotl/guts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GUTS - Go UTilitieS

Go Reference

  • Conversions from/to []byte to/from various types.
  • Various bytes operations.
  • HexByte: []byte alias with MarshalJSON and UnmarshalJSON methods for hex encoding.

Error-related utilities.

ReadFromWriter

ReadFromWriter is the interface that groups the basic ReadFrom and Write methods.

ReadFromWriteCloser

ReadFromWriteCloser is the interface that groups the basic ReadFrom, Write and Close methods.

WriteToReader

WriteToReader is the interface that groups the basic WriteTo and Read methods.

WriteToReadCloser

WriteToReadCloser is the interface that groups the basic WriteTo, Read and Close methods.

ReaderFromWriter

ReaderFromWriter is a type that wraps an io.ReaderFrom and implements ReadFromWriteCloser using io.Pipe. Due to the asynchronous nature of io.Pipe, Write() will only be guaranteed to be visible after a call to Sync() or Close().

WriterToReader

WriterToReader is a type that wraps an io.WriterTo implementation and implements WriteToReadCloser using io.Pipe.

ReadFromWriteToReadWriteCloser

ReadFromWriteToReadWriteCloser is the interface that groups the basic WriteTo, ReadFrom, Read, Write and Close methods.

ReaderFromWriteToReadWriteCloser

ReaderFromWriteToReadWriteCloser is a type that wraps an io.ReaderFrom and a io.WriterTo, and implements io.ReadWriteCloser, ReadFromWriteCloser and WriteToReadCloser using io.Pipe. Due to the asynchronous nature of io.Pipe, Write() will only be guaranteed to be visible after a call to Sync() or Close().

Connect(protoAddr string) (net.Conn, error)

Connect dials the given address and returns a net.Conn. The protoAddr argument should be prefixed with the protocol, eg. "tcp://127.0.0.1:8080" or "unix:///tmp/test.sock"

ProtocolAndAddress(listenAddr string) (string, string)

ProtocolAndAddress splits an address into the protocol and address components. For instance, "tcp://127.0.0.1:8080" will be split into "tcp" and "127.0.0.1:8080". If the address has no protocol prefix, the default is "tcp".

GetFreePort() (int, error)

GetFreePort gets a free port from the operating system.

TrapSignal(logger logger, cb func())

TrapSignal catches SIGTERM and SIGINT, executes the cleanup function, and exits with code 0.

Exit(s string)

Exit prints string s then os.Exit(1).

EnsureDir(dir string, mode os.FileMode) error

EnsureDir ensures the given directory exists, creating it if necessary. Errors if the path already exists as a non-directory.

FileExists(filePath string) bool

CopyFile(src, dst string) error

CopyFile copies a file. It truncates the destination file if it exists.

GetMACInterface() (iface *net.Interface, err error)

GetMACInterface returns the network interface associated with the MAC address of the host machine.

GetMACStr() (string, error)

GetMACStr returns the MAC address of the host machine.

GetMACUint64() (uint64, error)

GetMACStr returns the MAC address of the host machine represented in uint64.

Random number, string, bytes generation.

Package service/goprocesssrv is a service implementation based on goprocess that supports declaring and ensuring runtime dependencies between services.

Package service/suturesrv is a service implementation based on Suture.

Use sync.Mutex and sync.RWMutex from this package instead of sync so you can build your program with deadlock flag to detect deadlocks using go-deadklock.

ResultNotifier can be used for a goroutine to notify others that a job is done and pass the error occurred or nil if no error. It's based on sync.Cond.

License

Default license for the code in this library is MIT, see the source code for exceptions.

About

Go utility library

Topics

Resources

License

MIT, Apache-2.0 licenses found

Licenses found

MIT
LICENSE
Apache-2.0
LICENSE_APACHE_2.0

Stars

Watchers

Forks

Packages

No packages published

Languages