xassert

package
v0.0.0-...-5a98790 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2021 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(key, value string, defaultValue bool) (bool, error)

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

func BoolFromEnv(envVar string, defaultValue bool) (bool, error)

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

func Bytes(key, value string, defaultValue int64, rules ...RuleInt64) (int64, error)

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

func BytesFromEnv(envVar string, defaultValue int64, rules ...RuleInt64) (int64, error)

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

func Int64(key, value string, defaultValue int64, rules ...RuleInt64) (int64, error)

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

func Int64FromEnv(envVar string, defaultValue int64, rules ...RuleInt64) (int64, error)

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

func Int64NotInferiorTo(lowerBound int64) RuleInt64

Int64NotInferiorTo returns a RuleInt64 for validating that an int64 is not inferior to given lower bound.

func Int64NotSuperiorTo

func Int64NotSuperiorTo(upperBound int64) RuleInt64

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.

Jump to

Keyboard shortcuts

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