utils

package
v0.0.0-...-f4f6315 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2018 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package utils contains utility functions used in the coniks-go library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNthBit

func GetNthBit(bs []byte, offset uint32) bool

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

func LongToBytes(num int64) []byte

LongToBytes converts an int64 variable to byte array in little endian format.

func ResolvePath

func ResolvePath(file, other string) string

ResolvePath returns the absolute path of file. This will use other as a base path if file is just a file name.

func ToBits

func ToBits(bs []byte) []bool

ToBits converts a slice of bytes into a slice of bits. In each byte, the bits are ordered MSB to LSB.

func ToBytes

func ToBytes(bits []bool) []byte

ToBytes converts a slice of bits into a slice of bytes. In each byte, the bits are ordered MSB to LSB.

func UInt32ToBytes

func UInt32ToBytes(num uint32) []byte

UInt32ToBytes converts an uint32 variable to byte array in little endian format.

func ULongToBytes

func ULongToBytes(num uint64) []byte

ULongToBytes converts an uint64 variable to byte array in little endian format.

func WithDB

func WithDB(f func(kv.DB))

WithDB is used to run tests with a database backend. It creates a temporary directory named "merkletree" in the system's tmp directory and then creates an empty key-value database. This temporary directory will be removed after this function returns.

func WriteFile

func WriteFile(filename string, buf []byte, perm os.FileMode) error

WriteFile writes buf to a file whose path is indicated by filename.

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

func (l *Logger) Debug(msg string, keysAndValues ...interface{})

Debug logs a message that is most useful to debug, with some additional context addressed by key-value pairs.

func (*Logger) Error

func (l *Logger) Error(msg string, keysAndValues ...interface{})

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) Fatal

func (l *Logger) Fatal(msg string, keysAndValues ...interface{})

Fatal is the same as Panic but it then calls os.Exit instead.

func (*Logger) Info

func (l *Logger) Info(msg string, keysAndValues ...interface{})

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.

func (*Logger) Panic

func (l *Logger) Panic(msg string, keysAndValues ...interface{})

Panic logs a message that is a severe error event, leads the application to abort, with some additional context addressed by key-value pairs. It then panics.

func (*Logger) Warn

func (l *Logger) Warn(msg string, keysAndValues ...interface{})

Warn logs a message that indicates potentially harmful situations, 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL