Documentation ¶
Overview ¶
Package xassert is a helper for converting and/or validating strings.
All functions return our standard xerror.Error in case of error.
Index ¶
- func Bool(key, value string, defaultValue bool) (bool, error)
- func BoolFromEnv(envVar string, defaultValue bool) (bool, error)
- func Bytes(key, value string, defaultValue int64, rules ...RuleInt64) (int64, error)
- func BytesFromEnv(envVar string, defaultValue int64, rules ...RuleInt64) (int64, error)
- func Float64(key, value string, defaultValue float64, rules ...RuleFloat64) (float64, error)
- func Float64FromEnv(envVar string, defaultValue float64, rules ...RuleFloat64) (float64, error)
- func Int64(key, value string, defaultValue int64, rules ...RuleInt64) (int64, error)
- func Int64FromEnv(envVar string, defaultValue int64, rules ...RuleInt64) (int64, error)
- func String(key, value, defaultValue string, rules ...RuleString) (string, error)
- func StringFromEnv(envVar, defaultValue string, rules ...RuleString) (string, error)
- type RuleFloat64
- type RuleInt64
- type RuleString
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool tries to convert a string to a boolean.
If string is empty or conversion fails, returns the default value.
The key is used to identify the value.
func BoolFromEnv ¶
BoolFromEnv returns the boolean representation of the value of given environment variable.
If not found, empty or conversion fails, returns the default value.
func Bytes ¶
Bytes tries to convert a string to a int64.
If string is empty or conversion fails, returns the default value.
The key is used to identify the value.
func BytesFromEnv ¶
BytesFromEnv returns the int64 representation of the value of given environment variable.
If not found, empty or conversion fails, returns the default value.
func Float64 ¶
func Float64(key, value string, defaultValue float64, rules ...RuleFloat64) (float64, error)
Float64 tries to convert a string to a float64.
If string is empty, conversion or validation fails, returns the default value.
The key is used to identify the value.
func Float64FromEnv ¶
func Float64FromEnv(envVar string, defaultValue float64, rules ...RuleFloat64) (float64, error)
Float64FromEnv returns the float64 representation of the value of given environment variable.
If not found, empty, conversion or validation fails, returns the default value.
func Int64 ¶
Int64 tries to convert a string to an int64.
If string is empty, conversion or validation fails, returns the default value.
The key is used to identify the value.
func Int64FromEnv ¶
Int64FromEnv returns the int64 representation of the value of given environment variable.
If not found, empty, conversion or validation fails, returns the default value.
func String ¶
func String(key, value, defaultValue string, rules ...RuleString) (string, error)
String applies validation on a string.
If string is empty or validation fails, returns the default value.
The key is used to identify the value.
func StringFromEnv ¶
func StringFromEnv(envVar, defaultValue string, rules ...RuleString) (string, error)
StringFromEnv returns the value of given environment variable or the default value if not found or validation fails.
Types ¶
type RuleFloat64 ¶
type RuleFloat64 interface {
// contains filtered or unexported methods
}
RuleFloat64 is an interface for validating a float64.
func Float64NotInferiorTo ¶
func Float64NotInferiorTo(lowerBound float64) RuleFloat64
Float64NotInferiorTo returns a RuleFloat64 for validating that a float64 is not inferior to given lower bound.
func Float64NotSuperiorTo ¶
func Float64NotSuperiorTo(upperBound float64) RuleFloat64
Float64NotSuperiorTo returns a RuleFloat64 for validating that a float64 is not superior to given upper bound.
type RuleInt64 ¶
type RuleInt64 interface {
// contains filtered or unexported methods
}
RuleInt64 is an interface for validating an int64.
func Int64NotInferiorTo ¶
Int64NotInferiorTo returns a RuleInt64 for validating that an int64 is not inferior to given lower bound.
func Int64NotSuperiorTo ¶
Int64NotSuperiorTo returns a RuleInt64 for validating that an int64 is not superior to given upper bound.
type RuleString ¶
type RuleString interface {
// contains filtered or unexported methods
}
RuleString is an interface for validating a string.
func StringEndWith ¶
func StringEndWith(endWith string) RuleString
StringEndWith returns a RuleString for validating that a string ends with given string.
func StringOneOf ¶
func StringOneOf(values []string) RuleString
StringOneOf returns a RuleString for validating that a string is one of given values.
func StringStartWith ¶
func StringStartWith(startWith string) RuleString
StringStartWith returns a RuleString for validating that a string starts with given string.