Skip to content

Commit 84fe578

Browse files
authored
Merge pull request #342 from ErikKalkoken/feat-remove-set-slice
feat: replace Set:Slice() usage
2 parents 3fa4328 + 3e855d5 commit 84fe578

36 files changed

+93
-57
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
fyne.io/fyne/v2 v2.7.1
99
github.com/ErikKalkoken/eveauth v0.1.0
1010
github.com/ErikKalkoken/fyne-kx v0.6.4
11-
github.com/ErikKalkoken/go-set v0.1.0
11+
github.com/ErikKalkoken/go-set v0.2.0
1212
github.com/JohannesKaufmann/html-to-markdown v1.6.0
1313
github.com/PuerkitoBio/goquery v1.11.0
1414
github.com/anthonynsimon/bild v0.14.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ github.com/ErikKalkoken/go-set v0.0.0-20251218130435-a0521ce135e4 h1:sylpjAZjPyb
4747
github.com/ErikKalkoken/go-set v0.0.0-20251218130435-a0521ce135e4/go.mod h1:8hyYMuo2dqGaCGf32C/CILHMTVRJ9CV2vlcIPGOBe5I=
4848
github.com/ErikKalkoken/go-set v0.1.0 h1:oPQH/4oOMFMFyGRGHloo+Ey5/jepYIfFsnhK2W7Smb0=
4949
github.com/ErikKalkoken/go-set v0.1.0/go.mod h1:8hyYMuo2dqGaCGf32C/CILHMTVRJ9CV2vlcIPGOBe5I=
50+
github.com/ErikKalkoken/go-set v0.2.0 h1:qbeuoupUMuwnbHzGwXTeFXXC9m/WLAPeoDakyP6rLnw=
51+
github.com/ErikKalkoken/go-set v0.2.0/go.mod h1:8hyYMuo2dqGaCGf32C/CILHMTVRJ9CV2vlcIPGOBe5I=
5052
github.com/JohannesKaufmann/html-to-markdown v1.6.0 h1:04VXMiE50YYfCfLboJCLcgqF5x+rHJnb1ssNmqpLH/k=
5153
github.com/JohannesKaufmann/html-to-markdown v1.6.0/go.mod h1:NUI78lGg/a7vpEJTz/0uOcYMaibytE4BUOQS8k78yPQ=
5254
github.com/PuerkitoBio/goquery v1.9.2/go.mod h1:GHPCaP0ODyyxqcNoFGYlAprUFH81NuRPd0GX3Zu2Mvk=

internal/app/characterservice/assets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (s *CharacterService) updateAssetsESI(ctx context.Context, arg app.Characte
257257
}
258258
slog.Info("Stored character assets", "characterID", characterID, "created", created, "updated", updated)
259259
if ids := set.Difference(currentIDs, incomingIDs); ids.Size() > 0 {
260-
if err := s.st.DeleteCharacterAssets(ctx, characterID, ids.Slice()); err != nil {
260+
if err := s.st.DeleteCharacterAssets(ctx, characterID, ids); err != nil {
261261
return err
262262
}
263263
slog.Info("Deleted obsolete character assets", "characterID", characterID, "count", ids.Size())

internal/app/characterservice/assets_internal_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import (
99
"github.com/jarcoal/httpmock"
1010
"github.com/stretchr/testify/assert"
1111

12+
"github.com/ErikKalkoken/go-set"
13+
1214
"github.com/ErikKalkoken/evebuddy/internal/app"
1315
"github.com/ErikKalkoken/evebuddy/internal/app/storage"
1416
"github.com/ErikKalkoken/evebuddy/internal/app/testutil"
17+
"github.com/ErikKalkoken/evebuddy/internal/xassert"
1518
)
1619

1720
func TestUpdateCharacterAssetsESI(t *testing.T) {
@@ -156,7 +159,7 @@ func TestUpdateCharacterAssetsESI(t *testing.T) {
156159
assert.True(t, changed)
157160
ids, err := st.ListCharacterAssetIDs(ctx, c.ID)
158161
if assert.NoError(t, err) {
159-
assert.ElementsMatch(t, []int64{1000000016835, 1000000016836}, ids.Slice())
162+
xassert.EqualSet(t, set.Of[int64](1000000016835, 1000000016836), ids)
160163
}
161164
}
162165
})

internal/app/characterservice/character.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"log/slog"
8+
"slices"
89

910
"github.com/ErikKalkoken/go-set"
1011
"github.com/antihax/goesi/esi"
@@ -177,7 +178,7 @@ func (s *CharacterService) HasCharacter(ctx context.Context, id int32) (bool, er
177178
// The provided context is used for the SSO authentication process only and can be canceled.
178179
// the setInfo callback is used to update info text in a dialog.
179180
func (s *CharacterService) UpdateOrCreateCharacterFromSSO(ctx context.Context, setInfo func(s string)) (*app.Character, error) {
180-
ssoToken, err := s.authClient.Authorize(ctx, app.Scopes().Slice())
181+
ssoToken, err := s.authClient.Authorize(ctx, slices.Collect(app.Scopes().All()))
181182
if err != nil {
182183
return nil, err
183184
}

internal/app/characterservice/planets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (s *CharacterService) updatePlanetsESI(ctx context.Context, arg app.Charact
107107
}
108108
obsolete := set.Difference(existing, incoming)
109109
if obsolete.Size() > 0 {
110-
if err := s.st.DeleteCharacterPlanet(ctx, characterID, obsolete.Slice()); err != nil {
110+
if err := s.st.DeleteCharacterPlanet(ctx, characterID, obsolete); err != nil {
111111
return err
112112
}
113113
slog.Info("Removed obsolete planets", "characterID", characterID, "count", obsolete.Size())

internal/app/characterservice/search.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ import (
1616

1717
// AddEveEntitiesFromSearchESI runs a search on ESI and adds the results as new EveEntity objects to the database.
1818
// This method performs a character specific search and needs a token.
19-
func (s *CharacterService) AddEveEntitiesFromSearchESI(ctx context.Context, characterID int32, search string) ([]int32, error) {
19+
func (s *CharacterService) AddEveEntitiesFromSearchESI(ctx context.Context, characterID int32, search string) (set.Set[int32], error) {
20+
var z set.Set[int32]
2021
token, err := s.GetValidCharacterToken(ctx, characterID)
2122
if err != nil {
22-
return nil, err
23+
return z, err
2324
}
2425
categories := []string{
2526
"corporation",
@@ -30,15 +31,15 @@ func (s *CharacterService) AddEveEntitiesFromSearchESI(ctx context.Context, char
3031
ctx = xgoesi.NewContextWithOperationID(ctx, "GetCharactersCharacterIdSearch")
3132
r, _, err := s.esiClient.ESI.SearchApi.GetCharactersCharacterIdSearch(ctx, categories, characterID, search, nil)
3233
if err != nil {
33-
return nil, err
34+
return z, err
3435
}
3536
ids := set.Union(set.Of(r.Alliance...), set.Of(r.Character...), set.Of(r.Corporation...))
3637
missingIDs, err := s.eus.AddMissingEntities(ctx, ids)
3738
if err != nil {
3839
slog.Error("Failed to fetch missing IDs", "error", err)
39-
return nil, err
40+
return z, err
4041
}
41-
return missingIDs.Slice(), nil
42+
return missingIDs, nil
4243
}
4344

4445
// SearchESI performs a name search for items on the ESI server

internal/app/characterservice/skill_internal_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ import (
55
"fmt"
66
"testing"
77

8+
"github.com/ErikKalkoken/go-set"
9+
"github.com/jarcoal/httpmock"
10+
"github.com/stretchr/testify/assert"
11+
812
"github.com/ErikKalkoken/evebuddy/internal/app"
913
"github.com/ErikKalkoken/evebuddy/internal/app/storage"
1014
"github.com/ErikKalkoken/evebuddy/internal/app/testutil"
11-
"github.com/jarcoal/httpmock"
12-
"github.com/stretchr/testify/assert"
15+
"github.com/ErikKalkoken/evebuddy/internal/xassert"
1316
)
1417

1518
func TestGetAttributes(t *testing.T) {
@@ -188,7 +191,7 @@ func TestUpdateCharacterSkillsESI(t *testing.T) {
188191
assert.True(t, changed)
189192
ids, err := st.ListCharacterSkillIDs(ctx, c.ID)
190193
if assert.NoError(t, err) {
191-
assert.ElementsMatch(t, []int32{41}, ids.Slice())
194+
xassert.EqualSet(t, set.Of[int32](41), ids)
192195
}
193196
}
194197
})

internal/app/characterservice/skills.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func (s *CharacterService) updateSkillsESI(ctx context.Context, arg app.Characte
215215
}
216216
slog.Info("Stored updated character skills", "characterID", characterID, "count", len(skills.Skills))
217217
if ids := set.Difference(currentSkillIDs, incomingSkillIDs); ids.Size() > 0 {
218-
if err := s.st.DeleteCharacterSkills(ctx, characterID, ids.Slice()); err != nil {
218+
if err := s.st.DeleteCharacterSkills(ctx, characterID, ids); err != nil {
219219
return err
220220
}
221221
slog.Info("Deleted obsolete character skills", "characterID", characterID, "count", ids.Size())

internal/app/characterservice/token.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"log/slog"
7+
"slices"
78
"time"
89

910
"github.com/ErikKalkoken/eveauth"
@@ -120,7 +121,7 @@ func (s *CharacterService) ensureValidCharacterToken(ctx context.Context, token
120121
CharacterID: token.CharacterID,
121122
ExpiresAt: token.ExpiresAt,
122123
RefreshToken: token.RefreshToken,
123-
Scopes: token.Scopes.Slice(),
124+
Scopes: slices.Collect(token.Scopes.All()),
124125
TokenType: token.TokenType,
125126
}
126127
err := s.authClient.RefreshToken(ctx, token2)

0 commit comments

Comments
 (0)