types

package
v1.22.3 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 17

Documentation

Overview

Package types defines types used in events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

func Clone(v interface{}) interface{}

Clone v clones a CNE attribute value, which is one of the valid types:

bool, int32, string, []byte, types.URI, types.URIRef, types.Timestamp

Returns the same type Panics if the type is not valid

func Format

func Format(v interface{}) (string, error)

Format returns the canonical string format of v, where v can be any type that is convertible to a CNE type.

func FormatBinary

func FormatBinary(v []byte) string

FormatBinary returns canonical string format: standard base64 encoding

func FormatBool

func FormatBool(v bool) string

FormatBool returns canonical string format: "true" or "false"

func FormatFloat64

func FormatFloat64(v float64) string

FormatFloat64 returns canonical string format: decimal notation.

func FormatInteger

func FormatInteger(v int32) string

FormatInteger returns canonical string format: decimal notation.

func FormatTime

func FormatTime(v time.Time) string

FormatTime returns canonical string format: RFC3339 with nanoseconds

func IsZero

func IsZero(v interface{}) bool

IsZero check if the interface has zero value

func ParseBinary

func ParseBinary(v string) ([]byte, error)

ParseBinary parse canonical string format: standard base64 encoding

func ParseBool

func ParseBool(v string) (bool, error)

ParseBool parse canonical string format: "true" or "false"

func ParseInteger

func ParseInteger(v string) (int32, error)

ParseInteger parse canonical string format: decimal notation.

func ParseTime

func ParseTime(v string) (time.Time, error)

ParseTime parse canonical string format: RFC3339 with nanoseconds

func ToBinary

func ToBinary(v interface{}) ([]byte, error)

ToBinary returns a []byte value, decoding from base64 string if necessary.

func ToBool

func ToBool(v interface{}) (bool, error)

ToBool accepts a bool value or canonical "true"/"false" string.

func ToInteger

func ToInteger(v interface{}) (int32, error)

ToInteger accepts any numeric value in int32 range, or canonical string.

func ToString

func ToString(v interface{}) (string, error)

ToString returns a string value unaltered.

This function does not perform canonical string encoding, use one of the Format functions for that.

func ToTime

func ToTime(v interface{}) (time.Time, error)

ToTime returns a time.Time value, parsing from RFC3339 string if necessary.

func ToURL

func ToURL(v interface{}) (*url.URL, error)

ToURL returns a *url.URL value, parsing from string if necessary.

func Validate

func Validate(v interface{}) (interface{}, error)

Validate v is a valid CNE attribute value, convert it to one of:

bool, int32, string, []byte, types.URI, types.URIRef, types.Timestamp

Types

type ConvertErr

type ConvertErr struct {
	// Value being converted
	Value interface{}
	// Type of attempted conversion
	Type reflect.Type
	// contains filtered or unexported fields
}

ConvertErr convert error

func (*ConvertErr) Error

func (e *ConvertErr) Error() string

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp wraps time.Time to normalize the time layout to RFC3339. It is intended to enforce compliance with the Cloud Native events spec for their definition of Timestamp. Custom marshal methods are implemented to ensure the outbound Timestamp is a string in the RFC3339 layout.

func ParseTimestamp

func ParseTimestamp(s string) (*Timestamp, error)

ParseTimestamp attempts to parse the given time assuming RFC3339 layout

func (*Timestamp) MarshalJSON

func (t *Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom json marshal method used when this type is marshaled using json.Marshal.

func (*Timestamp) MarshalXML

func (t *Timestamp) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements a custom xml marshal method used when this type is marshaled using xml.Marshal.

func (Timestamp) String

func (t Timestamp) String() string

String outputs the time using RFC3339 format.

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json unmarshal method used when this type is unmarshalled using json.Unmarshal.

func (*Timestamp) UnmarshalXML

func (t *Timestamp) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml unmarshal method used when this type is unmarshaled using xml.Unmarshal.

type URI

type URI struct {
	url.URL
}

URI is a wrapper to url.URL. It is intended to enforce compliance with the Cloud Native Events spec for their definition of URI. Custom marshal methods are implemented to ensure the outbound URI object is a flat string.

func ParseURI

func ParseURI(u string) *URI

ParseURI attempts to parse the given string as a URI.

func (URI) MarshalJSON

func (u URI) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom json marshal method used when this type is marshaled using json.Marshal.

func (URI) MarshalXML

func (u URI) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements a custom xml marshal method used when this type is marshaled using xml.Marshal.

func (*URI) String

func (u *URI) String() string

String returns the full string representation of the URI-Reference.

func (*URI) UnmarshalJSON

func (u *URI) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json unmarshal method used when this type is unmarshaled using json.Unmarshal.

func (*URI) UnmarshalXML

func (u *URI) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml unmarshal method used when this type is unmarshaled using xml.Unmarshal.

func (URI) Validate

func (u URI) Validate() bool

Validate url value

Jump to

Keyboard shortcuts

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