diff --git a/app/controller/cutil/form.go b/app/controller/cutil/form.go index 958d8fa8..90508e0e 100644 --- a/app/controller/cutil/form.go +++ b/app/controller/cutil/form.go @@ -35,8 +35,7 @@ func ParseFormAsChanges(rc *fasthttp.RequestCtx) (util.ValueMap, error) { } func parseJSONForm(rc *fasthttp.RequestCtx) (util.ValueMap, error) { - var ret any - err := util.FromJSON(rc.Request.Body(), &ret) + ret, err := util.FromJSONInterface(rc.Request.Body()) if err != nil { return nil, errors.Wrap(err, "can't parse JSON body") } diff --git a/app/lib/log/encoder.go b/app/lib/log/encoder.go index 228b708e..32270345 100644 --- a/app/lib/log/encoder.go +++ b/app/lib/log/encoder.go @@ -36,8 +36,7 @@ func (e *customEncoder) EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) out := b.Bytes() b.Free() - data := util.ValueMap{} - err = util.FromJSON(out, &data) + data, err := util.FromJSONMap(out) if err != nil { return nil, errors.Wrap(err, "can't parse logging JSON") } diff --git a/app/util/json.go b/app/util/json.go index 1d6e1d49..06ada3c7 100644 --- a/app/util/json.go +++ b/app/util/json.go @@ -38,6 +38,18 @@ func FromJSON(msg json.RawMessage, tgt any) error { return jsoniterParser.Unmarshal(msg, tgt) } +func FromJSONString(msg json.RawMessage) (string, error) { + var tgt string + err := jsoniterParser.Unmarshal(msg, &tgt) + return tgt, err +} + +func FromJSONMap(msg json.RawMessage) (ValueMap, error) { + var tgt ValueMap + err := jsoniterParser.Unmarshal(msg, &tgt) + return tgt, err +} + func FromJSONInterface(msg json.RawMessage) (any, error) { var tgt any err := FromJSON(msg, &tgt)