Skip to content

Conversation

jo3-l
Copy link
Contributor

@jo3-l jo3-l commented May 19, 2024

As suggested in #dev-discussion, permit the sort template function to index (exported) struct fields, so that code like

{{ sort .Guild.Roles (sdict "key" "Position") }}

just works, instead of erroring with cannot index value of type discordgo.Role.

Note that the proposed patch still does not support niladic method calls. Hence, code like {{ sort $sliceOfTimes (sdict "key" "Hour") }} remains an error, since Hour is a method on time.Time, not a field. Ideally, we would lift this restriction and completely align the implementation of the key option with field access in templates, such that {{ sort $xs (sdict "key" "K") }} corresponds to sorting by $x.K. This behavior, however, is much more difficult to implement so is not done in this PR (and it is debatable whether it is worth the added complexity.)

@ashishjh-bst ashishjh-bst merged commit 34c4fa4 into botlabs-gg:dev May 20, 2024
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.

2 participants