Documentation ¶
Index ¶
- Constants
- Variables
- func ComposeErrors(errs ...error) error
- func CopyDir(source, dest string) error
- func CopyFile(source, dest string) error
- func Critical(v ...interface{})
- func ExtendErr(s string, err error) error
- func ExtractTarGz(filename, dir string) error
- func JoinErrors(errs []error, sep string) error
- func Retry(tries int, durationBetweenAttempts time.Duration, fn func() error) (err error)
- func Select(v Var) interface{}
- func Severe(v ...interface{})
- func TempDir(dirs ...string) string
- type InvalidVersionError
- type ProtocolVersion
- type Var
Constants ¶
const DEBUG = false
const ( // EncodedVersionLength is the static length of a sia-encoded ProtocolVersion. EncodedVersionLength = 16 // sizeof(uint32==64) + sizeof([8]uint8) )
const Release = "standard"
Variables ¶
var ( // SiaTestingDir is the directory that contains all of the files and // folders created during testing. SiaTestingDir = filepath.Join(os.TempDir(), "SiaTesting") )
Functions ¶
func ComposeErrors ¶ added in v0.1.0
ComposeErrors will take multiple errors and compose them into a single errors with a longer message. Any nil errors used as inputs will be stripped out, and if there are zero non-nil inputs then 'nil' will be returned.
The original types of the errors is not preserved at all.
func Critical ¶
func Critical(v ...interface{})
Critical should be called if a sanity check has failed, indicating developer error. Critical is called with an extended message guiding the user to the issue tracker on Github. If the program does not panic, the call stack for the running goroutine is printed to help determine the error.
func ExtendErr ¶ added in v0.1.0
ExtendErr will return a new error which extends the input error with a string. If the input error is nil, then 'nil' will be returned, discarding the input string.
func ExtractTarGz ¶ added in v0.1.0
ExtractTarGz extracts the specified .tar.gz file to dir, overwriting existing files in the event of a name conflict.
func JoinErrors ¶
JoinErrors concatenates the elements of errs to create a single error. The separator string sep is placed between elements in the resulting error. Nil errors are skipped. If errs is empty or only contains nil elements, JoinErrors returns nil.
func Retry ¶ added in v1.0.2
Retry will call 'fn' 'tries' times, waiting 'durationBetweenAttempts' between each attempt, returning 'nil' the first time that 'fn' returns nil. If 'nil' is never returned, then the final error returned by 'fn' is returned.
func Select ¶ added in v0.1.0
func Select(v Var) interface{}
Select returns the field of v that corresponds to the current Release.
Since the caller typically makes a type assertion on the result, it is important to point out that type assertions are stricter than conversions. Specifically, you cannot write:
type myint int Select(Var{0, 0, 0}).(myint)
Because 0 will be interpreted as an int, which is not assignable to myint. Instead, you must explicitly cast each field in the Var, or cast the return value of Select after the type assertion. The former is preferred.
func Severe ¶
func Severe(v ...interface{})
Severe will print a message to os.Stderr. If DEBUG has been set panic will be called as well. Severe should be called in situations which indicate significant problems for the user (such as disk failure or random number generation failure), but where crashing is not strictly required to preserve integrity.
Types ¶
type InvalidVersionError ¶ added in v0.1.0
type InvalidVersionError string
InvalidVersionError indicates a protocol version is invalid.
func (InvalidVersionError) Error ¶ added in v0.1.0
func (e InvalidVersionError) Error() string
Error implements the error interface for InvalidVersionError.
type ProtocolVersion ¶ added in v0.1.0
type ProtocolVersion struct { Version uint32 // Semantic Versioning Prerelease [8]byte // Any pre-release tag (eg. 'alpha' or the git commit hash) }
ProtocolVersion defines the protocol version that a node uses
var ( // Version is the current version of rivined. Version ProtocolVersion )
func MustParse ¶ added in v0.1.1
func MustParse(raw string) ProtocolVersion
MustParse creates a version based on a given string, panics in case the given string is invalid
func NewPrereleaseVersion ¶ added in v0.1.0
func NewPrereleaseVersion(major, minor, patch uint8, prerelease string) ProtocolVersion
NewPrereleaseVersion creates a new protocol prerelease version
func NewVersion ¶ added in v0.1.0
func NewVersion(major, minor, patch uint8) ProtocolVersion
NewVersion creates a new protocol version
func Parse ¶ added in v0.1.1
func Parse(raw string) (ver ProtocolVersion, err error)
Parse attempts to create a version based on a given string
func (ProtocolVersion) Compare ¶ added in v0.1.0
func (pv ProtocolVersion) Compare(other ProtocolVersion) int
Compare returns an integer comparing this version with another version.
func (ProtocolVersion) MarshalJSON ¶ added in v0.1.0
func (pv ProtocolVersion) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.MarshalJSON
func (ProtocolVersion) String ¶ added in v0.1.0
func (pv ProtocolVersion) String() string
String returns the string version of this ProtocolVersion
func (*ProtocolVersion) UnmarshalJSON ¶ added in v0.1.0
func (pv *ProtocolVersion) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON
type Var ¶ added in v0.1.0
type Var struct { Standard interface{} Dev interface{} Testing interface{} // contains filtered or unexported fields }
A Var represents a variable whose value depends on which Release is being compiled. None of the fields may be nil, and all fields must have the same type.