build

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 17 Imported by: 2

README

Build

The build package contains high level helper functions.

Subsystems

Appdata

Key Files

The Appdata subsystem is responsible for providing information about various application data. This subsystem is used to interact with any environment variables that are set by the user.

Environment Variables

  • SIA_API_PASSWORD is the siaAPIPassword environment variable that sets a custom API password
  • SIA_DATA_DIR siaDataDir is the environment variable that tells spd where to put the general sia data, e.g. api password, configuration, logs, etc.
  • SIAD_DATA_DIR siadDataDir is the environment variable which tells spd where to put the spd-specific data
  • SIA_WALLET_PASSWORD is the siaWalletPassword environment variable that can enable auto unlocking the wallet

Build Flags

Key Files

TODO...

Commit

TODO...

Critical

TODO...

Errors

TODO...

Testing

TODO...

URL

Key Files

The URL subsystem is responsible for providing information about Sia URLs that are in use.

Var

TODO...

Version

TODO...

Documentation

Index

Constants

View Source
const (
	// EnvvarAPIPassword is the environment variable that sets a custom API
	// password if the default is not used
	EnvvarAPIPassword = "SCPRIME_API_PASSWORD" //nolint:gosec

	// EnvvarMetaDataDir is the environment variable that tells spd where to put the
	// sia data
	EnvvarMetaDataDir = "SCPRIME_DATA_DIR"

	// EnvvarWalletPassword is the environment variable that can be set to enable
	// auto unlocking the wallet
	EnvvarWalletPassword = "SCPRIME_WALLET_PASSWORD" //nolint:gosec

	// EnvvarDaemonDataDir is the environment variable which tells the daemon
	// where to put the daemon specific data
	EnvvarDaemonDataDir = "DAEMON_DATA_DIR"
)
View Source
const (
	// MaxEncodedVersionLength is the maximum length of a version string encoded
	// with the encode package. 100 is much larger than any version number we send
	// now, but it allows us to send additional information in the version string
	// later if we choose. For example appending the version string with the HEAD
	// commit hash.
	MaxEncodedVersionLength = 100

	// Version is the current version of ScPrime daemon.
	Version = "1.9.0"
)
View Source
const DEBUG = false

DEBUG set to false turns the debugging off

View Source
const IssuesURL = "https://gitlab.com/scpcorp/ScPrime/issues"

IssuesURL is the URL of the location where issues and bugs should be reported.

View Source
const POOL = false

POOL set to false disables a set of tests that require a running MySQL db set up for pool testing.

View Source
const Release = "standard"

Release refers to the standard release mode.

View Source
const VLONG = false

VLONG disables a set of test cases that take a very long time to run

Variables

View Source
var (
	// GitRevision is the git commit hash used when built
	GitRevision string
	// BuildTime is the date and time the build was completed
	BuildTime string
)

GitRevision and BuildTime get assigned via the Makefile when built.

View Source
var ReleaseTag string = "master"

ReleaseTag contains the release tag, such as "rc3". It is supplied at build time. For full releases, this string is blank.

View Source
var (
	// SiaTestingDir is the directory that contains all of the files and
	// folders created during testing.
	SiaTestingDir = filepath.Join(os.TempDir(), "SiaTesting")
)

Functions

func APIPassword added in v1.5.0

func APIPassword() (string, error)

APIPassword returns the API Password either from the environment variable or from the password file. If no environment variable is set and no file exists, a password file is created and that password is returned

func ComposeErrors added in v1.1.0

func ComposeErrors(errs ...error) error

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 CopyDir added in v1.0.0

func CopyDir(source, dest string) error

CopyDir copies a directory and all of its contents to the destination directory.

func CopyFile added in v1.0.0

func CopyFile(source, dest string) (err error)

CopyFile copies a file from a source to a destination.

func Critical added in v1.0.0

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 DefaultMetadataDir added in v1.5.0

func DefaultMetadataDir() string

DefaultMetadataDir returns the default data directory of spd. The values for supported operating systems are:

Linux: $HOME/.scprime MacOS: $HOME/Library/Application Support/ScPrime Windows: %LOCALAPPDATA%\ScPrime

func DefaultSiaPrimeDir added in v1.5.0

func DefaultSiaPrimeDir() string

DefaultSiaPrimeDir returns the default data directory of older ScPrime nodes. This method is used to migrate the metadata to the new default location. The values for supported operating systems are:

Linux: $HOME/.siaprime MacOS: $HOME/Library/Application Support/SiaPrime Windows: %LOCALAPPDATA%\SiaPrime

func ExtendErr added in v1.1.0

func ExtendErr(s string, err error) error

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 v1.2.0

func ExtractTarGz(filename, dir string) (err error)

ExtractTarGz extracts the specified .tar.gz file to dir, overwriting existing files in the event of a name conflict.

func IsVersion added in v1.0.0

func IsVersion(str string) bool

IsVersion returns whether str is a valid version number.

func JoinErrors added in v1.0.0

func JoinErrors(errs []error, sep string) error

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.3.0

func Retry(tries int, durationBetweenAttempts time.Duration, fn func() error) (err error)

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 v1.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 added in v1.0.3

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.

func SiaDir added in v1.5.0

func SiaDir() string

SiaDir returns the ScPrime data directory either from the environment variable or the default.

func SiadDataDir added in v1.5.0

func SiadDataDir() string

SiadDataDir returns the data directory from the environment variable. If there is no environment variable it returns an empty string, instructing spd to store the consensus in the current directory.

func TempDir added in v0.3.2

func TempDir(dirs ...string) string

TempDir joins the provided directories and prefixes them with the ScPrime testing directory.

func VersionCmp added in v1.0.0

func VersionCmp(a, b string) int

VersionCmp returns an int indicating the difference between a and b. It follows the convention of bytes.Compare and big.Cmp:

-1 if a <  b
 0 if a == b
+1 if a >  b

One important quirk is that "1.1.0" is considered newer than "1.1", despite being numerically equal.

func WalletPassword added in v1.5.0

func WalletPassword() string

WalletPassword returns the SiaWalletPassword environment variable.

Types

type Var added in v1.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.

Jump to

Keyboard shortcuts

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