stringex

package
v0.0.0-...-a2846b3 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2016 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

The Tideland Go Library stringex package helps when working with strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PackageVersion

func PackageVersion() version.Version

PackageVersion returns the version of the version package.

Types

type Defaulter

type Defaulter interface {
	fmt.Stringer

	// AsString returns the value itself, only an error will
	// return the default.
	AsString(v Valuer, dv string) string

	// AsStringSlice returns the value as slice of strings
	// separated by the passed seperator.
	AsStringSlice(v Valuer, sep string, dv []string) []string

	// AsStringMap returns the value as map of strings to strings.
	// The rows are seperated by the rsep, the key/values per
	// row with kvsep.
	AsStringMap(v Valuer, rsep, kvsep string, dv map[string]string) map[string]string

	// AsBool returns the value interpreted as bool. Here the
	// strings 1, t, T, TRUE, true, True are interpreted as
	// true, the strings 0, f, F, FALSE, false, False as false.
	AsBool(v Valuer, dv bool) bool

	// AsInt returns the value interpreted as int.
	AsInt(v Valuer, dv int) int

	// AsInt64 returns the value interpreted as int64.
	AsInt64(v Valuer, dv int64) int64

	// AsUint returns the value interpreted as uint.
	AsUint(v Valuer, dv uint) uint

	// AsUint64 returns the value interpreted as uint64.
	AsUint64(v Valuer, dv uint64) uint64

	// AsFloat64 returns the value interpreted as float64.
	AsFloat64(v Valuer, dv float64) float64

	// AsTime returns the value interpreted as time in
	// the given layout.
	AsTime(v Valuer, layout string, dv time.Time) time.Time

	// AsDuration returns the value interpreted as duration.
	AsDuration(v Valuer, dv time.Duration) time.Duration
}

Defaulter provides an access to valuers interpreting the strings as types. In case of access or conversion errors these errors will be logged and the passed default values are returned.

func NewDefaulter

func NewDefaulter(id string, log bool) Defaulter

NewDefaulter creates a defaulter with the given settings.

type Valuer

type Valuer interface {
	// Value returns a string or a potential error during access.
	Value() (string, error)
}

Valuer describes returning a string value or an error if it does not exist are another access error happened.

Jump to

Keyboard shortcuts

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