intstr

package
v4.4.2 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IntOrString

type IntOrString struct {
	Type   Type
	IntVal int32
	StrVal string
}

IntOrString is a type that can hold an int32 or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a name or number. TODO: Rename to Int32OrString

+protobuf=true +protobuf.options.(gogoproto.goproto_stringer)=false +k8s:openapi-gen=true

func FromInt

func FromInt(val int) IntOrString

FromInt creates an IntOrString object with an int32 value. It is your responsibility not to call this method with a value greater than int32. TODO: convert to (val int32)

func FromString

func FromString(val string) IntOrString

FromString creates an IntOrString object with a string value.

func Parse

func Parse(val string) IntOrString

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

func (*IntOrString) Fuzz

func (intstr *IntOrString) Fuzz(c fuzz.Continue)

Fuzz satisfies fuzz.Interface

func (*IntOrString) IntValue

func (intstr *IntOrString) IntValue() int

IntValue returns the IntVal if type Int, or if it is a String, will attempt a conversion to int, returning 0 if a parsing error occurs.

func (IntOrString) MarshalJSON

func (intstr IntOrString) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface.

func (*IntOrString) String

func (intstr *IntOrString) String() string

String returns the string value, or the Itoa of the int value.

func (*IntOrString) UnmarshalJSON

func (intstr *IntOrString) UnmarshalJSON(value []byte) error

UnmarshalJSON implements the json.Unmarshaller interface.

type Type

type Type int64

Type represents the stored type of IntOrString.

const (
	Int    Type = iota // The IntOrString holds an int.
	String             // The IntOrString holds a string.
)

Jump to

Keyboard shortcuts

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