MCPcopy Create free account
hub / github.com/crossoverJie/gscript / JSONGet

Function JSONGet

internal_function.go:276–309  ·  view source on GitHub ↗
(v *Visitor, ctx *parser.FunctionCallContext)

Source from the content-addressed store, hash-verified

274}
275
276func JSONGet(v *Visitor, ctx *parser.FunctionCallContext) interface{} {
277 paramValues := v.buildParamValues(ctx)
278 p0 := paramValues[0]
279 p1 := paramValues[1]
280 var (
281 v1, v2 string
282 )
283 switch p0.(type) {
284 case *LeftValue:
285 value := p0.(*LeftValue).GetValue()
286 switch value.(type) {
287 case string:
288 v1 = fmt.Sprintf("%s", value)
289 default:
290 log.RuntimePanic(ctx, fmt.Sprintf("JSONGet JSON parameter are not a string: %v", reflect.TypeOf(value)))
291 }
292 case string:
293 v1 = fmt.Sprintf("%s", p0)
294 }
295 switch p1.(type) {
296 case *LeftValue:
297 value := p1.(*LeftValue).GetValue()
298 switch value.(type) {
299 case string:
300 v2 = fmt.Sprintf("%s", value)
301 default:
302 log.RuntimePanic(ctx, fmt.Sprintf("JSONGet path parameter are not a string: %v", reflect.TypeOf(value)))
303 }
304 case string:
305 v2 = fmt.Sprintf("%s", p1)
306 }
307 return xjson.Get(v1, v2).Raw()
308
309}
310
311func getCurrentTime(v *Visitor, ctx *parser.FunctionCallContext) interface{} {
312 tz, layout := v.getTzAndLayout(ctx)

Callers

nothing calls this directly

Calls 4

RuntimePanicFunction · 0.92
buildParamValuesMethod · 0.80
GetMethod · 0.80
GetValueMethod · 0.65

Tested by

no test coverage detected