groupware: downgrade to Go 1.25 since our building images are only available for 1.25 at the moment

* retrofit from using self-referencing generics parameters that were
   introduced with Go 1.26, will re-enable when we upgrade to 1.26

 * re-introduce a 'ptr' func since we don't have the new 'new' func yet
   that comes with 1.26
This commit is contained in:
Pascal Bleser
2026-06-18 16:49:11 +02:00
parent 153631d39f
commit 53795a0fb0
7 changed files with 68 additions and 44 deletions

2
go.mod
View File

@@ -1,6 +1,6 @@
module github.com/opencloud-eu/opencloud
go 1.26.0
go 1.25.0
require (
dario.cat/mergo v1.0.2

View File

@@ -59,8 +59,8 @@ func TestAddressBooks(t *testing.T) {
},
func(orig AddressBook) AddressBookChange {
return AddressBookChange{
Description: new(orig.Description + " (changed)"),
IsSubscribed: new(!orig.IsSubscribed),
Description: ptr(orig.Description + " (changed)"),
IsSubscribed: ptr(!orig.IsSubscribed),
}
},
func(t *testing.T, orig AddressBook, _ AddressBookChange, changed AddressBook) {
@@ -213,8 +213,8 @@ func TestContacts(t *testing.T) {
now := time.Now().Truncate(time.Duration(1) * time.Second).UTC()
for _, event := range expectedContactCardsById {
change := ContactCardChange{
Language: new("xyz"),
Updated: new(now),
Language: ptr("xyz"),
Updated: ptr(now),
}
result, err := s.client.UpdateContactCard(accountId, event.Id, change, ctx)
require.NoError(err)
@@ -401,11 +401,11 @@ func (s *StalwartTest) fillContacts( //NOSONAR
card := ContactCardChange{
Type: jscontact.ContactCardType,
Version: new(jscontact.JSContactVersion_1_0),
Version: ptr(jscontact.JSContactVersion_1_0),
AddressBookIds: toBoolPtrMap([]string{addressbookId}),
ProdId: &productName,
Language: &language,
Kind: new(jscontact.ContactCardKindIndividual),
Kind: ptr(jscontact.ContactCardKindIndividual),
Name: &nameObj,
}

View File

@@ -49,8 +49,8 @@ func TestCalendars(t *testing.T) { //NOSONAR
},
func(orig Calendar) CalendarChange {
return CalendarChange{
Description: new(orig.Description + " (changed)"),
IsSubscribed: new(!orig.IsSubscribed),
Description: ptr(orig.Description + " (changed)"),
IsSubscribed: ptr(!orig.IsSubscribed),
}
},
func(t *testing.T, orig Calendar, _ CalendarChange, changed Calendar) {
@@ -178,7 +178,7 @@ func TestEvents(t *testing.T) {
for _, event := range expectedEventsById {
change := CalendarEventChange{
EventChange: jscalendar.EventChange{
Status: new(jscalendar.StatusCancelled),
Status: ptr(jscalendar.StatusCancelled),
ObjectChange: jscalendar.ObjectChange{
Sequence: uintPtr(99),
ShowWithoutTime: truep,
@@ -467,7 +467,7 @@ func (s *StalwartTest) fillEvents( //NOSONAR
EventChange: jscalendar.EventChange{
Type: jscalendar.EventType,
Start: jscalendar.LocalDateTime(start),
Duration: new(jscalendar.Duration(duration)),
Duration: ptr(jscalendar.Duration(duration)),
Status: &status,
ObjectChange: jscalendar.ObjectChange{
CommonObjectChange: jscalendar.CommonObjectChange{

View File

@@ -1389,11 +1389,13 @@ type ChangesResponse[T Foo] interface {
GetDestroyed() []string
}
type QueryCommand[T Foo, SELF QueryCommand[T, SELF]] interface {
// TODO enable self-referencing generics parameter when upgrading to Go 1.26
// type QueryCommand[T Foo, SELF QueryCommand[T, SELF]] interface {
type QueryCommand[T Foo] interface {
JmapCommand
GetResponse() QueryResponse[T]
// Wither that creates a new object of the same type, keeping all the same values except for the limit that is specified as parameter.
WithLimit(limit *uint) SELF
WithLimit(limit *uint) QueryCommand[T] // TODO change return type to SELF when upgrading to Go 1.26
}
type QueryResponse[T Foo] interface {
@@ -1912,12 +1914,15 @@ type MailboxQueryCommand struct {
CalculateTotal bool `json:"calculateTotal,omitempty"`
}
var _ QueryCommand[Mailbox, MailboxQueryCommand] = &MailboxQueryCommand{}
// TODO enable self-referencing generics parameter when upgrading to Go 1.26
var _ QueryCommand[Mailbox /*, MailboxQueryCommand*/] = &MailboxQueryCommand{}
func (c MailboxQueryCommand) GetCommand() Command { return CommandMailboxQuery }
func (c MailboxQueryCommand) GetObjectType() ObjectType { return MailboxType }
func (c MailboxQueryCommand) GetResponse() QueryResponse[Mailbox] { return &MailboxQueryResponse{} }
func (c MailboxQueryCommand) WithLimit(limit *uint) MailboxQueryCommand {
// TODO enable self-referencing generics parameter when upgrading to Go 1.26
func (c MailboxQueryCommand) WithLimit(limit *uint) QueryCommand[Mailbox] /*MailboxQueryCommand*/ {
return MailboxQueryCommand{
AccountId: c.AccountId,
Filter: c.Filter,
@@ -2232,12 +2237,15 @@ type EmailQueryCommand struct {
CalculateTotal bool `json:"calculateTotal,omitempty"`
}
var _ QueryCommand[Email, EmailQueryCommand] = &EmailQueryCommand{}
// TODO enable self-referencing generics parameter when upgrading to Go 1.26
var _ QueryCommand[Email /*, EmailQueryCommand*/] = &EmailQueryCommand{}
func (c EmailQueryCommand) GetCommand() Command { return CommandEmailQuery }
func (c EmailQueryCommand) GetObjectType() ObjectType { return MailboxType }
func (c EmailQueryCommand) GetResponse() QueryResponse[Email] { return &EmailQueryResponse{} }
func (c EmailQueryCommand) WithLimit(limit *uint) EmailQueryCommand {
// TODO enable self-referencing generics parameter when upgrading to Go 1.26
func (c EmailQueryCommand) WithLimit(limit *uint) QueryCommand[Email] /*EmailQueryCommand*/ {
return EmailQueryCommand{
AccountId: c.AccountId,
Filter: c.Filter,
@@ -7203,14 +7211,17 @@ type ContactCardQueryCommand struct {
CalculateTotal bool `json:"calculateTotal,omitzero"`
}
var _ QueryCommand[ContactCard, ContactCardQueryCommand] = &ContactCardQueryCommand{}
// TODO enable self-referencing generics parameter when upgrading to Go 1.26
var _ QueryCommand[ContactCard /*, ContactCardQueryCommand*/] = &ContactCardQueryCommand{}
func (c ContactCardQueryCommand) GetCommand() Command { return CommandContactCardQuery }
func (c ContactCardQueryCommand) GetObjectType() ObjectType { return ContactCardType }
func (c ContactCardQueryCommand) GetResponse() QueryResponse[ContactCard] {
return &ContactCardQueryResponse{}
}
func (c ContactCardQueryCommand) WithLimit(limit *uint) ContactCardQueryCommand {
// TODO enable self-referencing generics parameter when upgrading to Go 1.26
func (c ContactCardQueryCommand) WithLimit(limit *uint) QueryCommand[ContactCard] /*ContactCardQueryCommand*/ {
return ContactCardQueryCommand{
AccountId: c.AccountId,
Filter: c.Filter,
@@ -7952,14 +7963,17 @@ type CalendarEventQueryCommand struct {
CalculateTotal bool `json:"calculateTotal,omitempty" doc:"opt" default:"false"`
}
var _ QueryCommand[CalendarEvent, CalendarEventQueryCommand] = &CalendarEventQueryCommand{}
// TODO enable self-referencing generics parameter when upgrading to Go 1.26
var _ QueryCommand[CalendarEvent /*, CalendarEventQueryCommand*/] = &CalendarEventQueryCommand{}
func (c CalendarEventQueryCommand) GetCommand() Command { return CommandCalendarEventQuery }
func (c CalendarEventQueryCommand) GetObjectType() ObjectType { return CalendarEventType }
func (c CalendarEventQueryCommand) GetResponse() QueryResponse[CalendarEvent] {
return &CalendarEventQueryResponse{}
}
func (c CalendarEventQueryCommand) WithLimit(limit *uint) CalendarEventQueryCommand {
// TODO enable self-referencing generics parameter when upgrading to Go 1.26
func (c CalendarEventQueryCommand) WithLimit(limit *uint) QueryCommand[CalendarEvent] /*CalendarEventQueryCommand*/ {
return CalendarEventQueryCommand{
AccountId: c.AccountId,
Filter: c.Filter,
@@ -8451,14 +8465,17 @@ type PrincipalQueryCommand struct {
CalculateTotal bool `json:"calculateTotal,omitzero"`
}
var _ QueryCommand[Principal, PrincipalQueryCommand] = &PrincipalQueryCommand{}
// TODO enable self-referencing generics parameter when upgrading to Go 1.26
var _ QueryCommand[Principal /*, PrincipalQueryCommand*/] = &PrincipalQueryCommand{}
func (c PrincipalQueryCommand) GetCommand() Command { return CommandPrincipalQuery }
func (c PrincipalQueryCommand) GetObjectType() ObjectType { return PrincipalType }
func (c PrincipalQueryCommand) GetResponse() QueryResponse[Principal] {
return &PrincipalQueryResponse{}
}
func (c PrincipalQueryCommand) WithLimit(limit *uint) PrincipalQueryCommand {
// TODO enable self-referencing generics parameter when upgrading to Go 1.26
func (c PrincipalQueryCommand) WithLimit(limit *uint) QueryCommand[Principal] /*PrincipalQueryCommand*/ {
return PrincipalQueryCommand{
AccountId: c.AccountId,
Filter: c.Filter,

View File

@@ -575,7 +575,7 @@ func (e Exemplar) MailboxInbox() (Mailbox, string, string) {
Id: e.MailboxInboxId,
Name: "Inbox",
Role: JmapMailboxRoleInbox,
SortOrder: new(0),
SortOrder: ptr(0),
TotalEmails: 1291,
UnreadEmails: 82,
TotalThreads: 891,
@@ -600,7 +600,7 @@ func (e Exemplar) MailboxInboxProjects() (Mailbox, string, string) {
Id: e.MailboxProjectId,
ParentId: e.MailboxInboxId,
Name: "Projects",
SortOrder: new(0),
SortOrder: ptr(0),
TotalEmails: 112,
UnreadEmails: 3,
TotalThreads: 85,
@@ -625,7 +625,7 @@ func (e Exemplar) MailboxDrafts() (Mailbox, string, string) {
Id: e.MailboxDraftsId,
Name: "Drafts",
Role: JmapMailboxRoleDrafts,
SortOrder: new(0),
SortOrder: ptr(0),
TotalEmails: 12,
UnreadEmails: 1,
TotalThreads: 12,
@@ -650,7 +650,7 @@ func (e Exemplar) MailboxSent() (Mailbox, string, string) {
Id: e.MailboxSentId,
Name: "Sent Items",
Role: JmapMailboxRoleSent,
SortOrder: new(0),
SortOrder: ptr(0),
TotalEmails: 1621,
UnreadEmails: 0,
TotalThreads: 1621,
@@ -675,7 +675,7 @@ func (e Exemplar) MailboxJunk() (Mailbox, string, string) {
Id: e.MailboxJunkId,
Name: "Junk Mail",
Role: JmapMailboxRoleJunk,
SortOrder: new(0),
SortOrder: ptr(0),
TotalEmails: 251,
UnreadEmails: 0,
TotalThreads: 251,
@@ -700,7 +700,7 @@ func (e Exemplar) MailboxDeleted() (Mailbox, string, string) {
Id: e.MailboxDeletedId,
Name: "Deleted Items",
Role: JmapMailboxRoleTrash,
SortOrder: new(0),
SortOrder: ptr(0),
TotalEmails: 99,
UnreadEmails: 0,
TotalThreads: 91,
@@ -918,7 +918,7 @@ func (e Exemplar) AddressBook() AddressBook {
func (e Exemplar) AddressBookChange() AddressBookChange {
return AddressBookChange{
Description: new("A different name"),
Description: ptr("A different name"),
}
}
@@ -2325,9 +2325,9 @@ func (e Exemplar) CalendarEventSearchResults() CalendarEventSearchResults {
return CalendarEventSearchResults{
Results: []CalendarEvent{ev},
CanCalculateChanges: true,
Position: new(uint(3)),
Limit: new(uint(10)),
Total: new(uint(4)),
Position: uintPtr(3),
Limit: uintPtr(10),
Total: uintPtr(4),
}
}
@@ -2337,8 +2337,8 @@ func (e Exemplar) ContactCardSearchResults() ContactCardSearchResults {
return ContactCardSearchResults{
Results: []ContactCard{c1, c2},
CanCalculateChanges: true,
Position: new(uint(3)),
Limit: new(uint(10)),
Total: new(uint(4)),
Position: uintPtr(3),
Limit: uintPtr(10),
Total: uintPtr(4),
}
}

View File

@@ -485,7 +485,8 @@ func query[T Foo, FILTER any, SORT any, QUERY QueryCommand[T], GET GetCommand[T]
}
*/
func queryN[T Foo, FILTER any, SORT any, QUERY QueryCommand[T, QUERY], GET GetCommand[T], QUERYRESP QueryResponse[T], GETRESP GetResponse[T], RESP any]( //NOSONAR
// TODO enable self-referencing generics parameter when upgrading to Go 1.26
func queryN[T Foo, FILTER any, SORT any, QUERY QueryCommand[T /*, QUERY*/], GET GetCommand[T], QUERYRESP QueryResponse[T], GETRESP GetResponse[T], RESP any]( //NOSONAR
client *Client, name string, objType ObjectType,
defaultSortBy []SORT,
queryCommandFactory func(accountId AccountId, queryParams QueryParams, limit *uint, filter FILTER, sortBy []SORT) QUERY,
@@ -504,11 +505,11 @@ func queryN[T Foo, FILTER any, SORT any, QUERY QueryCommand[T, QUERY], GET GetCo
invocations := make([]Invocation, len(accountIds)*2)
var g GET
var q QUERY
var q QueryCommand[T] // TODO change type to QUERY when upgrading to Go 1.26
{
i := 0
for accountId, queryParams := range accountIds {
query := queryCommandFactory(accountId, queryParams, limit, filter, sortBy)
var query QueryCommand[T] = queryCommandFactory(accountId, queryParams, limit, filter, sortBy) // TODO change type to QUERY when upgrading to Go 1.26
q = query
invocations[i*2+0] = invocation(query, mcid(accountId, "0"))
if limit != nil && *limit == 0 {

View File

@@ -245,7 +245,8 @@ func retrieveSet[T Foo, C SetCommand[T], R SetResponse[T]](ctx Context, data *Re
return retrieveResponseMatchParameters(ctx, data, command.GetCommand(), tag, target)
}
func retrieveQuery[T Foo, C QueryCommand[T, C], R QueryResponse[T]](ctx Context, data *Response, command C, tag string, target *R) Error {
// TODO enable self-referencing generics parameter when upgrading to Go 1.26
func retrieveQuery[T Foo, C QueryCommand[T /*, C*/], R QueryResponse[T]](ctx Context, data *Response, command C, tag string, target *R) Error {
return retrieveResponseMatchParameters(ctx, data, command.GetCommand(), tag, target)
}
@@ -394,8 +395,8 @@ func mapPairs[K comparable, L, R any](left map[K]L, right map[K]R) map[K]pair[L,
}
var (
truep = new(true)
falsep = new(false)
truep = ptr(true)
falsep = ptr(false)
)
func identity1[T any](t T) T {
@@ -406,10 +407,10 @@ func list[T Foo, GETRESP GetResponse[T]](r GETRESP) []T { return r.GetList() }
func getid[T Idable](r T) string { return r.GetId() }
func uintPtr[T int | uint](i T) *uint {
return new(uint(i))
return ptr(uint(i))
}
func valueIf[T any | uint | int | bool](value *T, condition bool) *T {
func valueIf[T any | uint | int | bool | any](value *T, condition bool) *T {
if condition {
return value
} else {
@@ -433,3 +434,8 @@ func ns(namespaces ...JmapNamespace) []JmapNamespace {
}
return result
}
// TODO remove and replace with calls to new() when upgrading to Go 1.26
func ptr[T any | int | uint | bool | string](t T) *T {
return &t
}