MCPcopy Create free account
hub / github.com/cel-expr/cel-go / valueToJSON

Function valueToJSON

codelab/solution/codelab.go:515–526  ·  view source on GitHub ↗

valueToJSON converts the CEL type to a protobuf JSON representation and marshals the result to a string.

(val ref.Val)

Source from the content-addressed store, hash-verified

513// valueToJSON converts the CEL type to a protobuf JSON representation and
514// marshals the result to a string.
515func valueToJSON(val ref.Val) string {
516 v, err := val.ConvertToNative(reflect.TypeOf(&structpb.Value{}))
517 if err != nil {
518 glog.Exit(err)
519 }
520 marshaller := protojson.MarshalOptions{Indent: " "}
521 bytes, err := marshaller.Marshal(v.(proto.Message))
522 if err != nil {
523 glog.Exit(err)
524 }
525 return string(bytes)
526}
527
528var (
529 emptyClaims = make(map[string]string)

Callers 1

exercise5Function · 0.70

Calls 1

ConvertToNativeMethod · 0.65

Tested by

no test coverage detected