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

Function valueToJSON

codelab/codelab.go:274–285  ·  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

272// valueToJSON converts the CEL type to a protobuf JSON representation and
273// marshals the result to a string.
274func valueToJSON(val ref.Val) string {
275 v, err := val.ConvertToNative(reflect.TypeOf(&structpb.Value{}))
276 if err != nil {
277 glog.Exit(err)
278 }
279 marshaller := protojson.MarshalOptions{Indent: " "}
280 bytes, err := marshaller.Marshal(v.(proto.Message))
281 if err != nil {
282 glog.Exit(err)
283 }
284 return string(bytes)
285}
286
287var (
288 emptyClaims = make(map[string]string)

Callers

nothing calls this directly

Calls 1

ConvertToNativeMethod · 0.65

Tested by

no test coverage detected