lib

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2020 License: ISC Imports: 9 Imported by: 0

Documentation

Overview

Package lib contains functions useful for most programs.

Index

Constants

View Source
const (
	// ExitSuccess is the successful exit status.
	//
	// It should be called on successful exit.
	ExitSuccess = 0

	// ExitFailure is the failing exit status.
	ExitFailure = 1
)

Variables

This section is empty.

Functions

func Duration

func Duration(d time.Duration) string

Duration returns a prettier string for time.Durations.

func Err

func Err(exit int, err error, format string, a ...interface{})

Err displays a formatting error message to standard error, appending the error string, and exits with the status code from `exit`, à la err(3).

func Errx

func Errx(exit int, format string, a ...interface{})

Errx displays a formatted error message to standard error and exits with the status code from `exit`, à la errx(3).

func Itoa

func Itoa(i int, wid int) string

Itoa provides cheap integer to fixed-width decimal ASCII. Give a negative width to avoid zero-padding. Adapted from the 'itoa' function in the log/log.go file in the standard library.

func LoadCertificate

func LoadCertificate(path string) (*x509.Certificate, error)

LoadCertificate tries to read a single certificate from disk. If the file contains multiple certificates (e.g. a chain), only the first certificate is returned.

func LoadCertificates

func LoadCertificates(path string) ([]*x509.Certificate, error)

LoadCertificates tries to read all the certificates in a file, returning them in the order that it found them in the file.

func ProgName

func ProgName() string

ProgName returns what lib thinks the program name is, namely the basename of of argv0.

It is similar to the Linux __progname function.

func ReadCertificate

func ReadCertificate(in []byte) (cert *x509.Certificate, rest []byte, err error)

ReadCertificate reads a DER or PEM-encoded certificate from the byte slice.

func ReadCertificates

func ReadCertificates(in []byte) (certs []*x509.Certificate, err error)

ReadCertificates tries to read all the certificates in a PEM-encoded collection.

func Warn

func Warn(err error, format string, a ...interface{}) (int, error)

Warn displays a formatted error message to standard output, appending the error string, à la warn(3).

func Warnx

func Warnx(format string, a ...interface{}) (int, error)

Warnx displays a formatted error message to standard error, à la warnx(3).

Types

type FileTime

type FileTime struct {
	Changed  time.Time
	Modified time.Time
	Accessed time.Time
}

FileTime contains the changed, modified, and accessed timestamps for a file.

func LoadFileTime

func LoadFileTime(path string) (FileTime, error)

LoadFileTime returns a FileTime associated with the file.

Jump to

Keyboard shortcuts

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