util

package
v0.0.0-...-ce94876 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2019 License: MIT, MIT Imports: 10 Imported by: 0

README

go-ipfs-util

standard-readme compliant

Common utilities used by go-ipfs and other related go packages

Install

This is a Go module which can be installed with go get github.com/ipfs/go-ipfs-util. go-ipfs-util is however packaged with Gx, so it is recommended to use Gx to install it (see Usage section).

Usage

This module is packaged with Gx. In order to use it in your own project do:

go get -u github.com/whyrusleeping/gx
go get -u github.com/whyrusleeping/gx-go
cd <your-project-repository>
gx init
gx import github.com/ipfs/go-ipfs-util
gx install --global
gx-go --rewrite

Please check Gx and Gx-go documentation for more information.

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

Want to hack on IPFS?

License

MIT

Documentation

Overview

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

Index

Constants

View Source
const DefaultIpfsHash = mh.SHA2_256

DefaultIpfsHash is the current default hash function used by IPFS.

Variables

View Source
var Debug bool

Debug is a global flag for debugging.

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.")

ErrSearchIncomplete 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 TimeFormatIpfs = time.RFC3339Nano

TimeFormatIpfs is the format ipfs uses to represent time in string form.

Functions

func ErrCast

func ErrCast() error

ErrCast is returned when a cast fails AND the program should not panic.

func ExpandPathnames

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

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

func FileExists

func FileExists(filename string) bool

FileExists check if the file with the given path exits.

func FormatRFC3339

func FormatRFC3339(t time.Time) string

FormatRFC3339 returns the string representation of the UTC value of the given time in RFC3339Nano format.

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 NewSeededRand

func NewSeededRand(seed int64) io.Reader

NewSeededRand returns a random bytes reader initialized with the given seed.

func NewTimeSeededRand

func NewTimeSeededRand() io.Reader

NewTimeSeededRand returns a random bytes reader which has been initialized with the current time.

func ParseRFC3339

func ParseRFC3339(s string) (time.Time, error)

ParseRFC3339 parses an RFC3339Nano-formatted time stamp and returns the UTC time.

func Partition

func Partition(subject string, sep string) (string, string, string)

Partition splits a subject 3 parts: prefix, separator, suffix. The first occurrence of the separator will be matched. ie. Partition("Ready, steady, go!", ", ") -> ["Ready", ", ", "steady, go!"]

func RPartition

func RPartition(subject string, sep string) (string, string, string)

RPartition splits a subject 3 parts: prefix, separator, suffix. The last occurrence of the separator will be matched. ie. RPartition("Ready, steady, go!", ", ") -> ["Ready, steady", ", ", "go!"]

func XOR

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

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

Types

type MultiErr

type MultiErr []error

MultiErr is a util to return multiple errors

func (MultiErr) Error

func (m MultiErr) Error() string

Jump to

Keyboard shortcuts

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