feat: use "GetTags" and "SetTags"

This commit is contained in:
sujit
2025-07-31 09:31:28 +05:45
parent d814019d73
commit 103e8f8d88
19 changed files with 1818 additions and 1069 deletions

45
utils/json.go Normal file
View File

@@ -0,0 +1,45 @@
package utils
import (
"github.com/oarkflow/json"
"github.com/oarkflow/json/jsonparser"
)
func RemoveFromJSONBye(jsonStr json.RawMessage, key ...string) json.RawMessage {
return jsonparser.Delete(jsonStr, key...)
}
func RemoveRecursiveFromJSON(jsonStr json.RawMessage, key ...string) json.RawMessage {
var data any
if err := json.Unmarshal(jsonStr, &data); err != nil {
return jsonStr
}
for _, k := range key {
data = removeKeyRecursive(data, k)
}
result, err := json.Marshal(data)
if err != nil {
return jsonStr
}
return result
}
func removeKeyRecursive(data any, key string) any {
switch v := data.(type) {
case map[string]any:
delete(v, key)
for k, val := range v {
v[k] = removeKeyRecursive(val, key)
}
return v
case []any:
for i, item := range v {
v[i] = removeKeyRecursive(item, key)
}
return v
default:
return v
}
}