event

package
v0.0.0-...-31600e6 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyExists          = errors.New("key already exists")
	ErrTargetKeyNotObject = errors.New("target key is not an object")
	ErrEmptyKey           = errors.New("key name is empty")
)
View Source
var NullValue = &Value{Type: NullType}

Functions

This section is empty.

Types

type Event

type Event struct {
	// contains filtered or unexported fields
}
Example
e := New()
e.Put("event.category", Array(String("network"), String("authentication")))
e.Put("event.type", Array(String("denied")))
e.Put("event.created", Timestamp(testTimeUnix))
e.Put("foo\\.bar", Integer(1))

data, err := json.MarshalIndent(e, "", "  ")
if err != nil {
	panic(err)
}

fmt.Println(string(data))
Output:

{
  "event": {
    "category": [
      "network",
      "authentication"
    ],
    "created": "2022-01-14T00:45:57.123456789Z",
    "type": [
      "denied"
    ]
  },
  "foo.bar": 1
}

func New

func New() *Event

New returns a new Event.

func (*Event) Delete

func (e *Event) Delete(key string) (deleted *Value)

Delete removes the given key. It returns the deleted value if it existed.

func (*Event) Get

func (e *Event) Get(key string) *Value

Get returns the value associated to the given key. It returns nil if the key does not exist.

func (*Event) MarshalJSON

func (e *Event) MarshalJSON() ([]byte, error)

func (*Event) Put

func (e *Event) Put(key string, val *Value) (old *Value, err error)

Put puts a value into the map. If the key already exists then it will be overwritten. If the target value is not an object then ErrTargetKeyNotObject is returned.

func (*Event) TryPut

func (e *Event) TryPut(key string, val *Value) (existing *Value, err error)

TryPut puts a value into the map if the key does not exist. If the key already exists it will return the existing value and ErrKeyExists. If the target value is not an object then ErrTargetKeyNotObject is returned.

func (*Event) UnmarshalJSON

func (e *Event) UnmarshalJSON(data []byte) error

type Time

type Time struct {
	UnixNanos int64
}

func TimeNow

func TimeNow() Time

func (Time) GoTime

func (t Time) GoTime() time.Time

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (Time) String

func (t Time) String() string

type Value

type Value struct {
	Integer         int64
	UnsignedInteger uint64
	Float           float64
	Timestamp       Time
	String          string
	Array           []*Value
	Object          map[string]*Value
	Bool            bool
	Type            ValueType
}

func Array

func Array(v ...*Value) *Value

func Bool

func Bool(v bool) *Value

func Float

func Float(v float64) *Value

func Integer

func Integer(v int64) *Value

func Object

func Object(v map[string]*Value) *Value

func String

func String(v string) *Value

func Timestamp

func Timestamp(unixNanos int64) *Value

func UnsignedInteger

func UnsignedInteger(v uint64) *Value

func (*Value) Format

func (v *Value) Format(f fmt.State, verb rune)

func (*Value) MarshalJSON

func (v *Value) MarshalJSON() ([]byte, error)

func (*Value) UnmarshalJSON

func (v *Value) UnmarshalJSON(data []byte) error

type ValueType

type ValueType uint8
const (
	NullType ValueType = iota
	ArrayType
	BoolType
	FloatType
	IntegerType
	ObjectType
	StringType
	TimestampType
	UnsignedIntegerType
)

func (ValueType) String

func (vt ValueType) String() string

Jump to

Keyboard shortcuts

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