Update dependencies and build to go1.22 (#2113)

* Update dependencies and build to go1.22

* Fix api changes wrt to dependencies

* Update golangci config
This commit is contained in:
Wim
2024-05-23 23:44:31 +02:00
committed by GitHub
parent 56e7bd01ca
commit 2f33fe86f5
1556 changed files with 3279522 additions and 1924375 deletions

View File

@@ -40,6 +40,12 @@ func (e *RichTextBlock) UnmarshalJSON(b []byte) error {
switch s.Type {
case RTESection:
elem = &RichTextSection{}
case RTEList:
elem = &RichTextList{}
case RTEQuote:
elem = &RichTextQuote{}
case RTEPreformatted:
elem = &RichTextPreformatted{}
default:
elems = append(elems, &RichTextUnknown{
Type: s.Type,
@@ -92,12 +98,92 @@ func (u RichTextUnknown) RichTextElementType() RichTextElementType {
return u.Type
}
type RichTextListElementType string
const (
RTEListOrdered RichTextListElementType = "ordered"
RTEListBullet RichTextListElementType = "bullet"
)
type RichTextList struct {
Type RichTextElementType `json:"type"`
Elements []RichTextElement `json:"elements"`
Style RichTextListElementType `json:"style"`
Indent int `json:"indent"`
}
// NewRichTextList returns a new rich text list element.
func NewRichTextList(style RichTextListElementType, indent int, elements ...RichTextElement) *RichTextList {
return &RichTextList{
Type: RTEList,
Elements: elements,
Style: style,
Indent: indent,
}
}
// ElementType returns the type of the Element
func (s RichTextList) RichTextElementType() RichTextElementType {
return s.Type
}
func (e *RichTextList) UnmarshalJSON(b []byte) error {
var raw struct {
RawElements []json.RawMessage `json:"elements"`
Style RichTextListElementType `json:"style"`
Indent int `json:"indent"`
}
if string(b) == "{}" {
return nil
}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
elems := make([]RichTextElement, 0, len(raw.RawElements))
for _, r := range raw.RawElements {
var s struct {
Type RichTextElementType `json:"type"`
}
if err := json.Unmarshal(r, &s); err != nil {
return err
}
var elem RichTextElement
switch s.Type {
case RTESection:
elem = &RichTextSection{}
case RTEList:
elem = &RichTextList{}
case RTEQuote:
elem = &RichTextQuote{}
case RTEPreformatted:
elem = &RichTextPreformatted{}
default:
elems = append(elems, &RichTextUnknown{
Type: s.Type,
Raw: string(r),
})
continue
}
if err := json.Unmarshal(r, elem); err != nil {
return err
}
elems = append(elems, elem)
}
*e = RichTextList{
Type: RTEList,
Elements: elems,
Style: raw.Style,
Indent: raw.Indent,
}
return nil
}
type RichTextSection struct {
Type RichTextElementType `json:"type"`
Elements []RichTextSectionElement `json:"elements"`
}
// ElementType returns the type of the Element
// RichTextElementType returns the type of the Element
func (s RichTextSection) RichTextElementType() RichTextElementType {
return s.Type
}
@@ -381,3 +467,62 @@ type RichTextSectionUnknownElement struct {
func (r RichTextSectionUnknownElement) RichTextSectionElementType() RichTextSectionElementType {
return r.Type
}
// RichTextQuote represents rich_text_quote element type.
type RichTextQuote RichTextSection
// RichTextElementType returns the type of the Element
func (s *RichTextQuote) RichTextElementType() RichTextElementType {
return s.Type
}
func (s *RichTextQuote) UnmarshalJSON(b []byte) error {
// reusing the RichTextSection struct, as it's the same as RichTextQuote.
var rts RichTextSection
if err := json.Unmarshal(b, &rts); err != nil {
return err
}
*s = RichTextQuote(rts)
s.Type = RTEQuote
return nil
}
// RichTextPreformatted represents rich_text_quote element type.
type RichTextPreformatted struct {
RichTextSection
Border int `json:"border"`
}
// RichTextElementType returns the type of the Element
func (s *RichTextPreformatted) RichTextElementType() RichTextElementType {
return s.Type
}
func (s *RichTextPreformatted) UnmarshalJSON(b []byte) error {
var rts RichTextSection
if err := json.Unmarshal(b, &rts); err != nil {
return err
}
// we define standalone fields because we need to unmarshal the border
// field. We can not directly unmarshal the data into
// RichTextPreformatted because it will cause an infinite loop. We also
// can not define a struct with embedded RichTextSection and Border fields
// because the json package will not unmarshal the data into the
// standalone fields, once it sees UnmarshalJSON method on the embedded
// struct. The drawback is that we have to process the data twice, and
// have to define a standalone struct with the same set of fields as the
// original struct, which may become a maintenance burden (i.e. update the
// fields in two places, should it ever change).
var standalone struct {
Border int `json:"border"`
}
if err := json.Unmarshal(b, &standalone); err != nil {
return err
}
*s = RichTextPreformatted{
RichTextSection: rts,
Border: standalone.Border,
}
s.Type = RTEPreformatted
return nil
}