utils

package
v0.0.0-...-00caeb1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2015 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TmpSuffix is the suffix for all temporary files.
	TmpSuffix = ".tmp"
)

Variables

View Source
var (
	// Trace is a logging interface for trace-level information.
	Trace *log.Logger
	// Info is a logging interface for info-level information.
	Info *log.Logger
	// Warning is a logging interface for warning-level information.
	Warning *log.Logger
	// Error is a logging interface for error-level information.
	Error *log.Logger

	// CurrentLoggerConfig holds the currently in use LoggerConfig.
	CurrentLoggerConfig LoggerConfig
	// DefaultLoggerConfig is a LoggerConfig where some logging levels are printed
	// to the console (errors to stderr, others to stdout).
	DefaultLoggerConfig = LoggerConfig{
		Trace:   []io.Writer{ioutil.Discard},
		Info:    []io.Writer{os.Stdout},
		Warning: []io.Writer{os.Stdout},
		Error:   []io.Writer{os.Stderr},
	}
)

Functions

func CompressData

func CompressData(data []byte) []byte

CompressData compresses bytes with the gzip algorithm.

func DecryptData

func DecryptData(input []byte, password string) []byte

DecryptData decrypts data using OpenPGP decryption.

func DecryptDataArmored

func DecryptDataArmored(input []byte, password string) []byte

DecryptDataArmored decrypts armored data using OpenPGP decryption.

func EncryptData

func EncryptData(input []byte, password string) []byte

EncryptData encrypts data using symmetric OpenPGP encryption.

func EncryptDataArmored

func EncryptDataArmored(input []byte, password string) []byte

EncryptDataArmored encrypts data using symmetric OpenPGP encryption. The result will be armored OpenPGP output.

func FileExists

func FileExists(filename string) bool

FileExists checks if a specified path (file or directory) exists.

func FixSlashes

func FixSlashes(input string) string

FixSlashes replaces all \ with / in a string.

func FormatFileSize

func FormatFileSize(bytes uint64) string

FormatFileSize converts file sizes in human-readable formats.

func GetDecryptCommand

func GetDecryptCommand(inputFile string, outputFile string, passwordFile string) string

GetDecryptCommand returns a Windows console command to decrypt a specific file that was encrypted with OpenPGP.

func GetHashSum

func GetHashSum(data []byte) string

GetHashSum returns the hash sum for data using the preferred algorithm (currently SHA-256).

func GetNewDocumentKey

func GetNewDocumentKey() string

GetNewDocumentKey returns 32 random bytes, encoded as a 64 byte hex string.

func InitLogger

func InitLogger(logDirectory string, quiet bool, verbose bool)

InitLogger initializes the logging configuration.

func MustWriteFile

func MustWriteFile(filename string, data []byte)

MustWriteFile writes data to filename. It panics if there is an error.

func MustWriteFileAtomic

func MustWriteFileAtomic(filename string, data []byte)

MustWriteFileAtomic first writes the data to a temporary file, then renames it.

func PanicIfErr

func PanicIfErr(err error)

PanicIfErr panics if the argument is not nil.

func ParseHumanRange

func ParseHumanRange(input string) (time.Duration, error)

ParseHumanRange parses human time ranges into time.Durations.

func UncompressData

func UncompressData(data []byte) []byte

UncompressData uncompresses bytes with the gzip algorithm.

Types

type Globfile

type Globfile struct {
	// contains filtered or unexported fields
}

Globfile holds a list of globs to match against.

func NewGlobfile

func NewGlobfile(filename string) (Globfile, error)

NewGlobfile reads globs from filename and returns a Globfile struct.

func (*Globfile) Len

func (g *Globfile) Len() int

Len returns the number of parsed globs.

func (*Globfile) Matches

func (g *Globfile) Matches(path string) bool

Matches checks if path matches one of the parsed globs.

type LoggerConfig

type LoggerConfig struct {
	Trace   []io.Writer
	Info    []io.Writer
	Warning []io.Writer
	Error   []io.Writer
}

LoggerConfig holds the output interfaces for the different logging levels.

Jump to

Keyboard shortcuts

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