Documentation ¶
Overview ¶
jsonutils package is utilities for handling JSON.
Index ¶
- type Decoder
- func (d *Decoder) Decode(s string, name string) []byte
- func (d *Decoder) Err() error
- func (d *Decoder) GetArray(name string) ([]any, bool)
- func (d *Decoder) GetBigInt(name string) (*big.Int, bool)
- func (d *Decoder) GetBytes(name string) ([]byte, bool)
- func (d *Decoder) GetInt64(name string) (int64, bool)
- func (d *Decoder) GetObject(name string) (map[string]any, bool)
- func (d *Decoder) GetString(name string) (string, bool)
- func (d *Decoder) GetStringArray(name string) ([]string, bool)
- func (d *Decoder) GetTime(name string) (time.Time, bool)
- func (d *Decoder) GetURL(name string) (*url.URL, bool)
- func (d *Decoder) Has(name string) bool
- func (d *Decoder) MustArray(name string) []any
- func (d *Decoder) MustBigInt(name string) *big.Int
- func (d *Decoder) MustBytes(name string) []byte
- func (d *Decoder) MustInt64(name string) int64
- func (d *Decoder) MustString(name string) string
- func (d *Decoder) SaveError(err error)
- type Encoder
- func (e *Encoder) Data() map[string]any
- func (e *Encoder) Encode(s []byte) string
- func (e *Encoder) Err() error
- func (e *Encoder) SaveError(err error)
- func (e *Encoder) Set(name string, v any)
- func (e *Encoder) SetBigInt(name string, i *big.Int)
- func (e *Encoder) SetBytes(name string, data []byte)
- func (e *Encoder) SetFixedBigInt(name string, i *big.Int, size int)
- func (e *Encoder) SetTime(name string, t time.Time)
- type NumericDate
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 ¶
NewDecoder returns a new Decoder. raw should be decoded by the json package.
func (*Decoder) Decode ¶
Decode decodes s as base64 raw url encoding. the returned slice is valid until next call.
func (*Decoder) GetArray ¶
GetArray gets an array parameter. If the parameter doesn't exist, it returns (nil, false).
func (*Decoder) GetBigInt ¶
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) GetBytes ¶
GetBytes gets a parameter of byte sequence base64-raw-url encoded. If the parameter doesn't exist, it returns (nil, false).
func (*Decoder) GetInt64 ¶
GetInt64 gets an integer parameter. If the parameter doesn't exist, it returns (0, false).
func (*Decoder) GetObject ¶
GetArray gets an object parameter. If the parameter doesn't exist, it returns (nil, false).
func (*Decoder) GetString ¶
GetString gets a string parameter. If the parameter doesn't exist, it returns ("", false).
func (*Decoder) GetStringArray ¶
GetArray gets a string array parameter. If the parameter doesn't exist, it returns (nil, false).
func (*Decoder) GetTime ¶
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 ¶
GetURL gets a url parameter. If the parameter doesn't exist, it returns (nil, false).
func (*Decoder) MustArray ¶
MustArray gets an array parameter. If the parameter doesn't exist, it returns nil and save the error.
func (*Decoder) MustBigInt ¶
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 ¶
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 ¶
MustInt64 gets an integer parameter. If the parameter doesn't exist, it returns nil and save the error.
func (*Decoder) MustString ¶
MustString gets a string parameter. If the parameter doesn't exist, it returns an empty string and save the error.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
func NewEncoder ¶
func (*Encoder) SaveError ¶
SaveError asserts the operation must not fail. If err is nil, SaveError does nothing. Otherwise, SaveError records the first error.
func (*Encoder) SetFixedBigInt ¶
type NumericDate ¶
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)