mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
bridgev2,error: use NonNilClone instead of creating map manually
This commit is contained in:
parent
329da10584
commit
77682fb292
4 changed files with 8 additions and 16 deletions
|
|
@ -19,6 +19,7 @@ import (
|
|||
|
||||
"github.com/rs/zerolog"
|
||||
"go.mau.fi/util/exfmt"
|
||||
"go.mau.fi/util/exmaps"
|
||||
"go.mau.fi/util/exslices"
|
||||
"go.mau.fi/util/exsync"
|
||||
"go.mau.fi/util/ptr"
|
||||
|
|
@ -4076,10 +4077,7 @@ func (portal *Portal) syncParticipants(
|
|||
Displayname: currentMember.Displayname,
|
||||
AvatarURL: currentMember.AvatarURL,
|
||||
}
|
||||
wrappedContent := &event.Content{Parsed: content, Raw: maps.Clone(member.MemberEventExtra)}
|
||||
if wrappedContent.Raw == nil {
|
||||
wrappedContent.Raw = make(map[string]any)
|
||||
}
|
||||
wrappedContent := &event.Content{Parsed: content, Raw: exmaps.NonNilClone(member.MemberEventExtra)}
|
||||
thisEvtSender := sender
|
||||
if member.Membership == event.MembershipJoin {
|
||||
content.Membership = event.MembershipInvite
|
||||
|
|
|
|||
12
error.go
12
error.go
|
|
@ -13,6 +13,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"go.mau.fi/util/exhttp"
|
||||
"go.mau.fi/util/exmaps"
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
|
|
@ -144,10 +145,7 @@ func (e *RespError) UnmarshalJSON(data []byte) error {
|
|||
}
|
||||
|
||||
func (e *RespError) MarshalJSON() ([]byte, error) {
|
||||
data := maps.Clone(e.ExtraData)
|
||||
if data == nil {
|
||||
data = make(map[string]any)
|
||||
}
|
||||
data := exmaps.NonNilClone(e.ExtraData)
|
||||
data["errcode"] = e.ErrCode
|
||||
data["error"] = e.Err
|
||||
return json.Marshal(data)
|
||||
|
|
@ -178,11 +176,7 @@ func (e RespError) WithStatus(status int) RespError {
|
|||
}
|
||||
|
||||
func (e RespError) WithExtraData(extraData map[string]any) RespError {
|
||||
if e.ExtraData == nil {
|
||||
e.ExtraData = make(map[string]any)
|
||||
} else {
|
||||
e.ExtraData = maps.Clone(e.ExtraData)
|
||||
}
|
||||
e.ExtraData = exmaps.NonNilClone(e.ExtraData)
|
||||
maps.Copy(e.ExtraData, extraData)
|
||||
return e
|
||||
}
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -17,7 +17,7 @@ require (
|
|||
github.com/tidwall/gjson v1.18.0
|
||||
github.com/tidwall/sjson v1.2.5
|
||||
github.com/yuin/goldmark v1.7.13
|
||||
go.mau.fi/util v0.9.2-0.20250928173307-c0b5f4ee5899
|
||||
go.mau.fi/util v0.9.2-0.20251001114608-d99877b9cc10
|
||||
go.mau.fi/zeroconfig v0.2.0
|
||||
golang.org/x/crypto v0.42.0
|
||||
golang.org/x/exp v0.0.0-20250911091902-df9299821621
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -51,8 +51,8 @@ github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
|
|||
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
|
||||
github.com/yuin/goldmark v1.7.13 h1:GPddIs617DnBLFFVJFgpo1aBfe/4xcvMc3SB5t/D0pA=
|
||||
github.com/yuin/goldmark v1.7.13/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
|
||||
go.mau.fi/util v0.9.2-0.20250928173307-c0b5f4ee5899 h1:GoPWdX45WrJG/NC+/6u4km9X9UvrzqGGG78z4VlXI7o=
|
||||
go.mau.fi/util v0.9.2-0.20250928173307-c0b5f4ee5899/go.mod h1:M0bM9SyaOWJniaHs9hxEzz91r5ql6gYq6o1q5O1SsjQ=
|
||||
go.mau.fi/util v0.9.2-0.20251001114608-d99877b9cc10 h1:EvX/di02gOriKN0xGDJuQ5mgiNdAF4LJc8moffI7Svo=
|
||||
go.mau.fi/util v0.9.2-0.20251001114608-d99877b9cc10/go.mod h1:M0bM9SyaOWJniaHs9hxEzz91r5ql6gYq6o1q5O1SsjQ=
|
||||
go.mau.fi/zeroconfig v0.2.0 h1:e/OGEERqVRRKlgaro7E6bh8xXiKFSXB3eNNIud7FUjU=
|
||||
go.mau.fi/zeroconfig v0.2.0/go.mod h1:J0Vn0prHNOm493oZoQ84kq83ZaNCYZnq+noI1b1eN8w=
|
||||
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue