jsonutils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

jsonutils package is utilities for handling JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder(pkg string, raw map[string]any) *Decoder

NewDecoder returns a new Decoder. raw should be decoded by the json package.

func (*Decoder) Decode

func (d *Decoder) Decode(s string, name string) []byte

Decode decodes s as base64 raw url encoding. the returned slice is valid until next call.

func (*Decoder) Err

func (d *Decoder) Err() error

Err returns the first error during decoding.

func (*Decoder) GetArray

func (d *Decoder) GetArray(name string) ([]any, bool)

GetArray gets an array parameter. If the parameter doesn't exist, it returns (nil, false).

func (*Decoder) GetBigInt

func (d *Decoder) GetBigInt(name string) (*big.Int, bool)

GetBigInt gets a big integer parameter. The parameter must be base64-raw-url encoded and big endian. If the parameter doesn't exist, it returns (nil, false).

func (*Decoder) GetBoolean added in v0.0.5

func (d *Decoder) GetBoolean(name string) (bool, bool)

GetString gets a boolean parameter. If the parameter doesn't exist, it returns (false, false).

func (*Decoder) GetBytes

func (d *Decoder) GetBytes(name string) ([]byte, bool)

GetBytes gets a parameter of byte sequence base64-raw-url encoded. If the parameter doesn't exist, it returns (nil, false).

func (*Decoder) GetInt64

func (d *Decoder) GetInt64(name string) (int64, bool)

GetInt64 gets an integer parameter. If the parameter doesn't exist, it returns (0, false).

func (*Decoder) GetObject

func (d *Decoder) GetObject(name string) (map[string]any, bool)

GetArray gets an object parameter. If the parameter doesn't exist, it returns (nil, false).

func (*Decoder) GetString

func (d *Decoder) GetString(name string) (string, bool)

GetString gets a string parameter. If the parameter doesn't exist, it returns ("", false).

func (*Decoder) GetStringArray

func (d *Decoder) GetStringArray(name string) ([]string, bool)

GetArray gets a string array parameter. If the parameter doesn't exist, it returns (nil, false).

func (*Decoder) GetTime

func (d *Decoder) GetTime(name string) (time.Time, bool)

GetTime gets a time parameter. The parameter must be a JSON number from UNIX time epoch in seconds. If the parameter doesn't exist, it returns (time.Time{}, false).

func (*Decoder) GetURL

func (d *Decoder) GetURL(name string) (*url.URL, bool)

GetURL gets a url parameter. If the parameter doesn't exist, it returns (nil, false).

func (*Decoder) Has

func (d *Decoder) Has(name string) bool

Has returns whether name parameter exists.

func (*Decoder) MustArray

func (d *Decoder) MustArray(name string) []any

MustArray gets an array parameter. If the parameter doesn't exist, it returns nil and save the error.

func (*Decoder) MustBigInt

func (d *Decoder) MustBigInt(name string) *big.Int

MustBigInt gets a big integer parameter. The parameter must be base64-raw-url encoded and big endian. If the parameter doesn't exist, it returns nil and save the error.

func (*Decoder) MustBytes

func (d *Decoder) MustBytes(name string) []byte

MustBytes gets a parameter of byte sequence base64-raw-url encoded. If the parameter doesn't exist, it returns nil and save the error.

func (*Decoder) MustInt64

func (d *Decoder) MustInt64(name string) int64

MustInt64 gets an integer parameter. If the parameter doesn't exist, it returns nil and save the error.

func (*Decoder) MustString

func (d *Decoder) MustString(name string) string

MustString gets a string parameter. If the parameter doesn't exist, it returns an empty string and save the error.

func (*Decoder) SaveError

func (d *Decoder) SaveError(err error)

SaveError asserts the operation must not fail. If err is nil, SaveError does nothing. Otherwise, SaveError records the first error.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

func NewEncoder

func NewEncoder(raw map[string]any) *Encoder

func (*Encoder) Data

func (e *Encoder) Data() map[string]any

func (*Encoder) Encode

func (e *Encoder) Encode(s []byte) string

func (*Encoder) Err

func (e *Encoder) Err() error

func (*Encoder) SaveError

func (e *Encoder) SaveError(err error)

SaveError asserts the operation must not fail. If err is nil, SaveError does nothing. Otherwise, SaveError records the first error.

func (*Encoder) Set

func (e *Encoder) Set(name string, v any)

func (*Encoder) SetBigInt

func (e *Encoder) SetBigInt(name string, i *big.Int)

func (*Encoder) SetBytes

func (e *Encoder) SetBytes(name string, data []byte)

func (*Encoder) SetFixedBigInt

func (e *Encoder) SetFixedBigInt(name string, i *big.Int, size int)

func (*Encoder) SetTime

func (e *Encoder) SetTime(name string, t time.Time)

type NumericDate

type NumericDate struct {
	time.Time
}

NumericDate represents a JSON numeric date value defined in RFC 7519 Section 2.

func (NumericDate) MarshalJSON

func (date NumericDate) MarshalJSON() (b []byte, err error)

func (*NumericDate) UnmarshalJSON

func (date *NumericDate) UnmarshalJSON(b []byte) (err error)

Jump to

Keyboard shortcuts

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