Skip to content

refactor: complete removal of go-linq/x/exp, modernize Go syntax#27

Merged
AWaterColorPen merged 2 commits intomainfrom
feature/phase1-go-modernize-v2
Apr 10, 2026
Merged

refactor: complete removal of go-linq/x/exp, modernize Go syntax#27
AWaterColorPen merged 2 commits intomainfrom
feature/phase1-go-modernize-v2

Conversation

@AWaterColorPen
Copy link
Copy Markdown
Owner

@AWaterColorPen AWaterColorPen commented Apr 6, 2026

Summary

Completes the removal of legacy dependencies started in the previous PR, and modernizes Go syntax throughout the codebase.

Changes

Dependency removal:

  • Remove all remaining go-linq usage in server.go, server_policy.go, server_user_domain.go, server_user_role.go
  • Replace golang.org/x/exp/constraints.Ordered with stdlib cmp.Ordered in Diff()
  • go-linq and golang.org/x/exp fully removed from go.mod after go mod tidy

Stdlib replacements:

  • linq.Distinct → stdlib-based distinct() generic helper (already in inheritance.go)
  • sort.Sliceslices.SortFunc in EdgeSorter.RootFirstSort and LeafFirstSort
  • DiffPolicy key map changed from map[any]*Policy to map[string]*Policy (type-safe)

Bug fix:

  • getSourceFeatureG2: initialize BFS queue with DefaultFeatureRootName (was empty before)

Readability:

  • Added // BFS: comments on growing-queue for-loops explaining the pattern

Spec:

  • Updated modernization spec to mark completed tasks

Test results

ok  github.com/awatercolorpen/caskin       8.292s
ok  github.com/awatercolorpen/caskin/playground  0.615s

Part of Phase 1 modernization plan.

- Remove all remaining go-linq usage in server.go, server_policy.go,
  server_user_domain.go, server_user_role.go
- Replace linq.Distinct with stdlib-based distinct() generic helper
- Replace golang.org/x/exp/constraints.Ordered with cmp.Ordered in Diff()
- Replace sort.Slice with slices.SortFunc in EdgeSorter methods
- Remove go-linq and golang.org/x/exp from go.mod (run go mod tidy)
- Add BFS comments on all growing-queue for-loops for clarity
- Fix getSourceFeatureG2: initialize queue with DefaultFeatureRootName
  (previous implementation had an empty queue bug)
- All existing tests pass

Part of Phase 1 modernization plan.
Copy link
Copy Markdown
Owner Author

@AWaterColorPen AWaterColorPen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Review — LGTM ✅

Clean modernization of the dependency removal. A few observations:

Strengths:

  • Diff[T] now uses explicit map lookups instead of go-linq reflection — clearer semantics and better performance.
  • LeafFirstSort reversal via cmp.Compare(e[b.V], e[a.V]) is correct (note: reversed b, a to achieve descending order).
  • distinct[T] defined in inheritance.go is a well-written generic helper, consistently reused in server_policy.go, server_user_domain.go, and server_user_role.go.
  • BFS comments added in object_directory.go, server_check.go, and server_feature_reset.go — good readability improvement.
  • go-linq and golang.org/x/exp fully removed from go.mod/go.sum. ✅
  • CI passes. ✅

Minor note:
The server_policy.go diff has a stray blank line after package caskin (empty import block left behind). Not a blocker but worth a quick cleanup.

Ready to merge once you are happy with it.

@AWaterColorPen AWaterColorPen merged commit 2adc300 into main Apr 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant