floatstr

package
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2025 License: Apache-2.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateFloat32OrString added in v2.4.0

func ValidateFloat32OrString(sl validator.StructLevel)

Types

type Float32OrString

type Float32OrString struct {
	Type     Type    `json:"type,omitempty"`
	FloatVal float32 `json:"floatVal,omitempty"`
	StrVal   string  `json:"strVal,omitempty"`
}

Float32OrString is a type that can hold a float32 or a string. implementation borrowed from apimachinary intstr package: https://github.com/kubernetes/apimachinery/blob/master/pkg/util/intstr/intstr.go

func FromFloat

func FromFloat(val float32) Float32OrString

FromFloat creates an Float32OrString object with a float32 value. It is your responsibility not to call this method with a value greater than float32.

func FromString

func FromString(val string) Float32OrString

FromString creates a Float32OrString object with a string value.

func Parse

func Parse(val string) Float32OrString

Parse the given string and try to convert it to a float32 before setting it as a string value.

func (*Float32OrString) FloatValue

func (floatstr *Float32OrString) FloatValue() float32

FloatValue returns the FloatVal if type float32, or if it is a String, will attempt a conversion to float32, returning 0 if a parsing error occurs.

func (*Float32OrString) MarshalJSON

func (floatstr *Float32OrString) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface.

func (*Float32OrString) String

func (floatstr *Float32OrString) String() string

String returns the string value, or the float value.

func (*Float32OrString) UnmarshalJSON

func (floatstr *Float32OrString) UnmarshalJSON(value []byte) error

UnmarshalJSON implements the json.Unmarshaller interface.

type Type

type Type int64

Type represents the stored type of Float32OrString.

const (
	// Float ...
	Float Type = iota // The Float32OrString holds a float.
	// String ...
	String // The Float32OrString holds a string.
)

Jump to

Keyboard shortcuts

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