typing

package
v0.0.0-...-89aa834 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package typing provides utilities for handling raw data objects and wraps basic Go types with additional functionality. It offers tools for flexible data processing and enhanced type manipulation, useful in various data handling and parsing scenarios.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool bool

Bool wraps a boolean value.

func (*Bool) Deref

func (b *Bool) Deref() bool

func (*Bool) Set

func (b *Bool) Set(v string) error

func (*Bool) SetValue

func (b *Bool) SetValue(v bool)

func (Bool) Value

func (b Bool) Value() bool

type Complex128

type Complex128 complex128

Complex128 wraps a complex128 value.

func (*Complex128) Deref

func (c *Complex128) Deref() complex128

func (*Complex128) Set

func (c *Complex128) Set(v string) error

func (*Complex128) SetValue

func (c *Complex128) SetValue(v complex128)

func (Complex128) Value

func (c Complex128) Value() complex128

type Complex64

type Complex64 complex64

Complex64 wraps a complex64 value.

func (*Complex64) Deref

func (c *Complex64) Deref() complex64

func (*Complex64) Set

func (c *Complex64) Set(v string) error

func (*Complex64) SetValue

func (c *Complex64) SetValue(v complex64)

func (Complex64) Value

func (c Complex64) Value() complex64

type Duration

type Duration time.Duration

Duration wraps a time.Duration value.

Example
d := Duration(5 * time.Second)
fmt.Println("Duration:", d.Value())

jsonData, _ := json.Marshal(d)
fmt.Println("JSON:", string(jsonData))

var parsed Duration
_ = parsed.Set("10m")
fmt.Println("Parsed:", parsed.Deref())
Output:

Duration: 5s
JSON: "5s"
Parsed: 10m0s

func (*Duration) Deref

func (d *Duration) Deref() time.Duration

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) Set

func (d *Duration) Set(v string) error

func (*Duration) SetValue

func (d *Duration) SetValue(v time.Duration)

func (Duration) String

func (d Duration) String() string

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(data []byte) error

func (Duration) Value

func (d Duration) Value() time.Duration

type Float32

type Float32 float32

Float32 wraps a float32 value.

func (*Float32) Deref

func (f *Float32) Deref() float32

func (*Float32) Set

func (f *Float32) Set(v string) error

func (*Float32) SetValue

func (f *Float32) SetValue(v float32)

func (Float32) Value

func (f Float32) Value() float32

type Float64

type Float64 float64

Float64 wraps a float64 value.

func (*Float64) Deref

func (f *Float64) Deref() float64

func (*Float64) Set

func (f *Float64) Set(v string) error

func (*Float64) SetValue

func (f *Float64) SetValue(v float64)

func (Float64) Value

func (f Float64) Value() float64

type Int

type Int int

Int wraps an integer value.

func (*Int) Deref

func (i *Int) Deref() int

func (*Int) Set

func (i *Int) Set(v string) error

func (*Int) SetValue

func (i *Int) SetValue(v int)

func (Int) Value

func (i Int) Value() int

type Int16

type Int16 int16

Int16 wraps an int16 value.

func (*Int16) Deref

func (i *Int16) Deref() int16

func (*Int16) Set

func (i *Int16) Set(v string) error

func (*Int16) SetValue

func (i *Int16) SetValue(v int16)

func (Int16) Value

func (i Int16) Value() int16

type Int32

type Int32 int32

Int32 wraps an int32 value.

func (*Int32) Deref

func (i *Int32) Deref() int32

func (*Int32) Set

func (i *Int32) Set(v string) error

func (*Int32) SetValue

func (i *Int32) SetValue(v int32)

func (Int32) Value

func (i Int32) Value() int32

type Int64

type Int64 int64

Int64 wraps an int64 value.

func (*Int64) Deref

func (i *Int64) Deref() int64

func (*Int64) Set

func (i *Int64) Set(v string) error

func (*Int64) SetValue

func (i *Int64) SetValue(v int64)

func (Int64) Value

func (i Int64) Value() int64

type Int8

type Int8 int8

Int8 wraps an int8 value.

func (*Int8) Deref

func (i *Int8) Deref() int8

func (*Int8) Set

func (i *Int8) Set(v string) error

func (*Int8) SetValue

func (i *Int8) SetValue(v int8)

func (Int8) Value

func (i Int8) Value() int8

type Object

type Object map[string]any

Object wraps a map[string]any value.

func (Object) Delete

func (o Object) Delete(key string)

func (Object) Get

func (o Object) Get(key string) any

func (Object) Keys

func (o Object) Keys() []string

func (Object) Len

func (o Object) Len() int

func (Object) Set

func (o Object) Set(key string, value any)

type RawObject

type RawObject []byte

RawObject represents a raw object for delayed JSON decoding.

Example
ro := NewRawObject(`{"name":"John","age":30}`)
fmt.Println("Raw JSON:", ro)

var person struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
}
err := ro.Decode(json.Unmarshal, &person)
if err != nil {
	fmt.Println("Error:", err)
	return
}
fmt.Printf("Decoded: Name=%s, Age=%d\n", person.Name, person.Age)
Output:

Raw JSON: {"name":"John","age":30}
Decoded: Name=John, Age=30

func NewRawObject

func NewRawObject[T ~string | ~[]byte](v T) RawObject

NewRawObject creates a new RawObject with the provided data.

func (RawObject) Bytes

func (o RawObject) Bytes() []byte

Bytes returns the raw byte slice of the Object.

func (RawObject) Decode

func (o RawObject) Decode(decoder encoding.Decoder, v any) error

Decode decodes the Object's data using the provided decoder. It does nothing and returns nil if the Object is empty.

func (RawObject) Len

func (o RawObject) Len() int

Len returns the length of the Object's data.

func (RawObject) MarshalBinary

func (o RawObject) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (RawObject) MarshalJSON

func (o RawObject) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. It returns the raw JSON encoding of the Object.

func (RawObject) MarshalText

func (o RawObject) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface. It returns the base64 encoding of the Object's data.

func (*RawObject) SetBytes

func (o *RawObject) SetBytes(b []byte)

SetBytes sets the raw byte slice of the Object.

func (*RawObject) SetString

func (o *RawObject) SetString(s string)

SetString sets the string representation of the Object.

func (RawObject) String

func (o RawObject) String() string

String returns the string representation of the Object.

func (*RawObject) UnmarshalBinary

func (o *RawObject) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*RawObject) UnmarshalJSON

func (o *RawObject) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. It sets the Object's data to a copy of the input JSON data.

func (*RawObject) UnmarshalText

func (o *RawObject) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface. It decodes the input text as base64 and sets the Object's data to the result.

type String

type String string

String wraps a string value.

func (*String) Deref

func (s *String) Deref() string

func (*String) Set

func (s *String) Set(v string) error

func (*String) SetValue

func (s *String) SetValue(v string)

func (String) Value

func (s String) Value() string

type Time

type Time time.Time

Time wraps a time.Time value.

func (*Time) Deref

func (t *Time) Deref() time.Time

func (*Time) Set

func (t *Time) Set(v string) error

func (*Time) SetValue

func (t *Time) SetValue(v time.Time)

func (Time) Value

func (t Time) Value() time.Time

type Uint

type Uint uint

Uint wraps an unsigned integer value.

func (*Uint) Deref

func (u *Uint) Deref() uint

func (*Uint) Set

func (u *Uint) Set(v string) error

func (*Uint) SetValue

func (u *Uint) SetValue(v uint)

func (Uint) Value

func (u Uint) Value() uint

type Uint16

type Uint16 uint16

Uint16 wraps an uint16 value.

func (*Uint16) Deref

func (u *Uint16) Deref() uint16

func (*Uint16) Set

func (u *Uint16) Set(v string) error

func (*Uint16) SetValue

func (u *Uint16) SetValue(v uint16)

func (Uint16) Value

func (u Uint16) Value() uint16

type Uint32

type Uint32 uint32

Uint32 wraps an uint32 value.

func (*Uint32) Deref

func (u *Uint32) Deref() uint32

func (*Uint32) Set

func (u *Uint32) Set(v string) error

func (*Uint32) SetValue

func (u *Uint32) SetValue(v uint32)

func (Uint32) Value

func (u Uint32) Value() uint32

type Uint64

type Uint64 uint64

Uint64 wraps an uint64 value.

func (*Uint64) Deref

func (u *Uint64) Deref() uint64

func (*Uint64) Set

func (u *Uint64) Set(v string) error

func (*Uint64) SetValue

func (u *Uint64) SetValue(v uint64)

func (Uint64) Value

func (u Uint64) Value() uint64

type Uint8

type Uint8 uint8

Uint8 wraps an uint8 value.

func (*Uint8) Deref

func (u *Uint8) Deref() uint8

func (*Uint8) Set

func (u *Uint8) Set(v string) error

func (*Uint8) SetValue

func (u *Uint8) SetValue(v uint8)

func (Uint8) Value

func (u Uint8) Value() uint8

Jump to

Keyboard shortcuts

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