util

package
v0.0.0-...-c9e5fdf Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2014 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

package util implements various utility functions used within ipfs that do not currently have a better place to live.

Index

Constants

This section is empty.

Variables

View Source
var B58KeyConverter = b58KeyConverter{}

B58KeyConverter -- for KeyTransform datastores (static as only one obj needed)

View Source
var Debug bool

Debug is a global flag for debugging.

View Source
var ErrNoSuchLogger = errors.New("Error: No such logger")

ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger

View Source
var ErrNotFound = ds.ErrNotFound

ErrNotFound is returned when a search fails to find anything

View Source
var ErrNotImplemented = errors.New("Error: not implemented yet.")

ErrNotImplemented signifies a function has not been implemented yet.

View Source
var ErrSearchIncomplete = errors.New("Error: Search Incomplete.")

ErrSeErrSearchIncomplete implies that a search type operation didnt find the expected node, but did find 'a' node.

View Source
var ErrTimeout = errors.New("Error: Call timed out.")

ErrTimeout implies that a timeout has been triggered

View Source
var LogFormats = map[string]string{
	"nocolor": "%{time:2006-01-02 15:04:05.000000} %{level} %{module} %{shortfile}: %{message}",
	"color": ansiGray + "%{time:15:04:05.000} %{color}%{level:5.5s} " + ansiBlue +
		"%{module:10.10s}: %{color:reset}%{message} " + ansiGray + "%{shortfile}%{color:reset}",
}

LogFormats is a map of formats used for our logger, keyed by name.

Functions

func B58KeyEncode

func B58KeyEncode(k Key) string

B58KeyEncode returns Key in a b58 encoded string

func ContextDo

func ContextDo(ctx context.Context, f func() error) error

func ContextWithErrorLog

func ContextWithErrorLog(parent context.Context) (context.Context, <-chan error)

ContextWithErrorLog returns a copy of parent and an error channel that can be used to receive errors sent with the LogError method.

func ExpandPathnames

func ExpandPathnames(paths []string) ([]string, error)

ExpandPathnames takes a set of paths and turns them into absolute paths

func GetenvBool

func GetenvBool(name string) bool

GetenvBool is the way to check an env var as a boolean

func Hash

func Hash(data []byte) mh.Multihash

Hash is the global IPFS hash function. uses multihash SHA2_256, 256 bits

func IsValidHash

func IsValidHash(s string) bool

IsValidHash checks whether a given hash is valid (b58 decodable, len > 0)

func LogError

func LogError(ctx context.Context, err error)

LogError logs the error to the owner of the context.

If this context was created with ContextWithErrorLog, then this method passes the error to context creator over an unbuffered channel.

If this context was created by other means, this method is a no-op.

func Logger

func Logger(name string) *logging.Logger

Logger retrieves a particular logger

func NewByteChanReader

func NewByteChanReader(in chan []byte) io.Reader

func NewTimeSeededRand

func NewTimeSeededRand() io.Reader

func POut

func POut(format string, a ...interface{})

POut is a shorthand printing function to output to Stdout.

func SetAllLoggers

func SetAllLoggers(lvl logging.Level)

SetAllLoggers changes the logging.Level of all loggers to lvl

func SetLogLevel

func SetLogLevel(name, level string) error

SetLogLevel changes the log level of a specific subsystem name=="*" changes all subsystems

func SetupLogging

func SetupLogging()

SetupLogging will initialize the logger backend and set the flags.

func TildeExpansion

func TildeExpansion(filename string) (string, error)

TildeExpansion expands a filename, which may begin with a tilde.

func XOR

func XOR(a, b []byte) []byte

XOR takes two byte slices, XORs them together, returns the resulting slice.

Types

type Key

type Key string

Key is a string representation of multihash for use with maps.

func B58KeyDecode

func B58KeyDecode(s string) Key

B58KeyDecode returns Key from a b58 encoded string

func KeyFromDsKey

func KeyFromDsKey(dsk ds.Key) Key

KeyFromDsKey returns a Datastore key

func (Key) B58String

func (k Key) B58String() string

B58String returns Key in a b58 encoded string

func (Key) DsKey

func (k Key) DsKey() ds.Key

DsKey returns a Datastore key

func (*Key) MarshalJSON

func (k *Key) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON-encoded Key (string)

func (Key) Pretty

func (k Key) Pretty() string

Pretty returns Key in a b58 encoded string TODO: deprecate Pretty. bad name.

func (Key) String

func (k Key) String() string

String is utililty function for printing out keys as strings (Pretty).

func (*Key) UnmarshalJSON

func (k *Key) UnmarshalJSON(mk []byte) error

UnmarshalJSON returns a JSON-encoded Key (string)

type KeySet

type KeySet interface {
	Add(Key)
	Remove(Key)
	Keys() []Key
}

func NewKeySet

func NewKeySet() KeySet

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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