From 84f72864605ba10ba879f3466627b4e9056f2a13 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Wed, 9 Apr 2025 01:06:49 +0100 Subject: [PATCH] Make Get return decorated result This may break existing widgets that rely on .Get returing a raw gjson.Result --- internal/glance/widget-custom-api.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/internal/glance/widget-custom-api.go b/internal/glance/widget-custom-api.go index 5d82c5a..a7e836e 100644 --- a/internal/glance/widget-custom-api.go +++ b/internal/glance/widget-custom-api.go @@ -311,7 +311,7 @@ func gJsonResultArrayToDecoratedResultArray(results []gjson.Result) []decoratedG } func (r *decoratedGJSONResult) Exists(key string) bool { - return r.Get(key).Exists() + return r.Result.Get(key).Exists() } func (r *decoratedGJSONResult) Array(key string) []decoratedGJSONResult { @@ -319,7 +319,7 @@ func (r *decoratedGJSONResult) Array(key string) []decoratedGJSONResult { return gJsonResultArrayToDecoratedResultArray(r.Result.Array()) } - return gJsonResultArrayToDecoratedResultArray(r.Get(key).Array()) + return gJsonResultArrayToDecoratedResultArray(r.Result.Get(key).Array()) } func (r *decoratedGJSONResult) String(key string) string { @@ -327,7 +327,7 @@ func (r *decoratedGJSONResult) String(key string) string { return r.Result.String() } - return r.Get(key).String() + return r.Result.Get(key).String() } func (r *decoratedGJSONResult) Int(key string) int { @@ -335,7 +335,7 @@ func (r *decoratedGJSONResult) Int(key string) int { return int(r.Result.Int()) } - return int(r.Get(key).Int()) + return int(r.Result.Get(key).Int()) } func (r *decoratedGJSONResult) Float(key string) float64 { @@ -343,7 +343,7 @@ func (r *decoratedGJSONResult) Float(key string) float64 { return r.Result.Float() } - return r.Get(key).Float() + return r.Result.Get(key).Float() } func (r *decoratedGJSONResult) Bool(key string) bool { @@ -351,7 +351,11 @@ func (r *decoratedGJSONResult) Bool(key string) bool { return r.Result.Bool() } - return r.Get(key).Bool() + return r.Result.Get(key).Bool() +} + +func (r *decoratedGJSONResult) Get(key string) *decoratedGJSONResult { + return &decoratedGJSONResult{r.Result.Get(key)} } func customAPIDoMathOp[T int | float64](a, b T, op string) T {