Documentation
¶
Overview ¶
Package utils contains utility functions used in the coniks-go library.
Index ¶
- func GetNthBit(bs []byte, offset uint32) bool
- func LongToBytes(num int64) []byte
- func ResolvePath(file, other string) string
- func ToBits(bs []byte) []bool
- func ToBytes(bits []bool) []byte
- func UInt32ToBytes(num uint32) []byte
- func ULongToBytes(num uint64) []byte
- func WithDB(f func(kv.DB))
- func WriteFile(filename string, buf []byte, perm os.FileMode) error
- type Logger
- func (l *Logger) Debug(msg string, keysAndValues ...interface{})
- func (l *Logger) Error(msg string, keysAndValues ...interface{})
- func (l *Logger) Fatal(msg string, keysAndValues ...interface{})
- func (l *Logger) Info(msg string, keysAndValues ...interface{})
- func (l *Logger) Panic(msg string, keysAndValues ...interface{})
- func (l *Logger) Warn(msg string, keysAndValues ...interface{})
- type LoggerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetNthBit ¶
GetNthBit finds the bit in the byte array bs at offset, and determines whether it is 1 or 0. It returns true if the nth bit is 1, false otherwise.
func LongToBytes ¶
LongToBytes converts an int64 variable to byte array in little endian format.
func ResolvePath ¶
ResolvePath returns the absolute path of file. This will use other as a base path if file is just a file name.
func ToBits ¶
ToBits converts a slice of bytes into a slice of bits. In each byte, the bits are ordered MSB to LSB.
func ToBytes ¶
ToBytes converts a slice of bits into a slice of bytes. In each byte, the bits are ordered MSB to LSB.
func UInt32ToBytes ¶
UInt32ToBytes converts an uint32 variable to byte array in little endian format.
func ULongToBytes ¶
ULongToBytes converts an uint64 variable to byte array in little endian format.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a wrapper for zap.SugaredLogger.
func NewLogger ¶
func NewLogger(conf *LoggerConfig) *Logger
NewLogger builds an instance of Logger with default configurations. This logger writes DebugLevel and above logs in development environment, InfoLevel and above logs in production environment to stderr and the file specified in conf, in a human-friendly format.
func (*Logger) Debug ¶
Debug logs a message that is most useful to debug, with some additional context addressed by key-value pairs.
func (*Logger) Error ¶
Error logs a message that is fatal to the operation, but not the service or application, and forces admin intervention, with some additional context addressed by key-value pairs. This still allow the application to continue running.
func (*Logger) Info ¶
Info logs a message that highlights the progress of the application and generally can be ignored under normal circumstances, with some additional context addressed by key-value pairs.
type LoggerConfig ¶
type LoggerConfig struct { EnableStacktrace bool `toml:"enable_stacktrace,omitempty"` Environment string `toml:"env"` Path string `toml:"path,omitempty"` }
A LoggerConfig contains the running environment which is either "development" or "production", the path of file to write the logging output to, and an option to explicitly enable stracktrace output.