intstr

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package intstr implements a custom type for handling values that can be either a string or an int32

Index

Constants

View Source
const NullValue = IntOrString("")

NullValue is an empty IntOrString value

Variables

This section is empty.

Functions

This section is empty.

Types

type IntOrString

type IntOrString string

IntOrString holds a value that can be either a string or a int

func FromInt32

func FromInt32(value int32) IntOrString

FromInt32 return a IntOrString from a int32

func FromString

func FromString(value string) IntOrString

FromString return a IntOrString from a string

func (IntOrString) AsPercentage

func (value IntOrString) AsPercentage() (int32, bool)

AsPercentage return the value of a string transformed in a percentage and reports if this conversion was possible. '10%' return 10 and true, while "10", "foo" return 0 and false.

func (IntOrString) Int32

func (value IntOrString) Int32() int32

Int32 returns the value of the IntOrString as an int32. If the current value is not an string, 0 is returned

func (IntOrString) IsInt

func (value IntOrString) IsInt() bool

IsInt returns true if the value is an integer

func (IntOrString) IsNull

func (value IntOrString) IsNull() bool

IsNull checks if the IntOrString value is the Int NullValue

func (IntOrString) IsZero

func (value IntOrString) IsZero() bool

IsZero checks if the IntOrString value is an integer 0

func (IntOrString) Str

func (value IntOrString) Str() string

Str returns the value of the IntOrString as a string.

func (IntOrString) Type

func (value IntOrString) Type() ValueType

Type returns the ValueType of a IntOrString value

type ValueType

type ValueType int

ValueType defines the type of a IntOrString value

const (
	// ValueTypeInt is a IntOrString that represents an integer value
	ValueTypeInt ValueType = iota
	// ValueTypeString is a IntOrString that represents a string value
	ValueTypeString
)

Jump to

Keyboard shortcuts

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