cel

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: MIT Imports: 13 Imported by: 0

README

cel-go

cel extend for go

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeLib

func ComputeLib() cel.EnvOption

func Val2Bytes

func Val2Bytes(val ref.Val) (out []byte, err error)
Example
package main

import (
	"fmt"

	"github.com/google/cel-go/common/types"
	compute "github.com/iotxfoundry/cel-go"
)

func main() {
	reg, err := types.NewRegistry()
	if err != nil {
		return
	}

	val := types.NewDynamicMap(reg, map[string]int64{"10000": 1})
	out, err := compute.Val2Bytes(val)
	if err != nil {
		return
	}
	fmt.Printf("% 02X\n", out)
	fmt.Println(string(out))
}
Output:

7B 22 31 30 30 30 30 22 3A 31 7D
{"10000":1}

func Val2Pb

func Val2Pb(val ref.Val) (out *structpb.Value, err error)
Example
package main

import (
	"encoding/json"
	"fmt"

	"github.com/google/cel-go/common/types"
	compute "github.com/iotxfoundry/cel-go"
)

func main() {
	reg, err := types.NewRegistry()
	if err != nil {
		return
	}

	val := types.NewDynamicMap(reg, map[string]int64{"10000": 1})
	out, err := compute.Val2Pb(val)
	if err != nil {
		return
	}
	buff, err := json.Marshal(out)
	if err != nil {
		return
	}
	fmt.Println(string(buff))
}
Output:

{"10000":1}

func Val2String

func Val2String(val ref.Val) (out string, err error)
Example
package main

import (
	"fmt"

	"github.com/google/cel-go/common/types"
	compute "github.com/iotxfoundry/cel-go"
)

func main() {
	reg, err := types.NewRegistry()
	if err != nil {
		return
	}

	val := types.NewDynamicMap(reg, map[string]int64{"10000": 1})
	out, err := compute.Val2String(val)
	if err != nil {
		return
	}
	fmt.Println(out)
}
Output:

{"10000":1}

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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