-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add access to regexp capturing group Inside URL rewriter #1973
Add access to regexp capturing group Inside URL rewriter #1973
Conversation
- add additional level for $tyc_context trigger keys - $tyk_context.trigger-{n}-{name}-{i}-{groupNum} holds group value Fixes TykTechnologies#1833
@buger |
Nice one! @dencoded can you pls review? |
Thank you a lot for all changes! @dencoded does it looks good to you? |
Hi, at this very moment i'm removing repeating/unused code in cached regexp implementation. |
Better new PR, to separate feature thing from refactoring itself. Thank you! |
mw_url_rewrite.go
Outdated
return strings.Join(parts, triggerKeySep) | ||
} | ||
|
||
func addGroupsToContextData(cd *map[string]interface{}, keyPrefix string, groups []string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need to pass map as pointer as maps (and slices) are passed by reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, for me this one looks suspicious.
Intent of addGroupsToContextData
is to modify (add items to) passed map.
As far as i know, in golang everything is value and passed by value (copied). Slices can look like passed by reference, because internally they holds pointer to baking array, first item index, length and capacity.
It can feels like they passed by reference (in case of modifying existing values), but in case of adding items they not. What's why append()
returns updated slice.
https://play.golang.org/p/arTxwX1w9mf
I've checked same approach with map and it works, probably because in essence map is just a pointer to underlying structure - i don't know.
Will remove pointers to map as requested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is tricky one - slices are different because they have len
and cap
in addition to pointer to underlaying array with elements, so when we pass it to function it receives new "descriptor" of slice but original pointer to elements.
if we do append inside function we have to return slice and re-assign result on calling side, otherwise calling part will hold slice-descriptor with appended elements but old len
and cap
(thats why Println outputs only one element). you can find more info about that situation here https://golang.org/doc/effective_go.html#slices
Changing elements would work if your slice is pre-allocated, i.e.:
https://play.golang.org/p/ZoK7WLz_Xtw
That's actually how all functions like func Read(slice []interface{}) (int, error)
reading data into passed slice without any explicit pointers.
But my comment was about maps, they work differently.
- extract regexp match handling into function
- add additional level for $tyc_context trigger keys - $tyk_context.trigger-{n}-{name}-{i}-{groupNum} holds group value Fixes #1833
- add additional level for $tyc_context trigger keys - $tyk_context.trigger-{n}-{name}-{i}-{groupNum} holds group value Fixes #1833
…gies#1973) - add additional level for $tyc_context trigger keys - $tyk_context.trigger-{n}-{name}-{i}-{groupNum} holds group value Fixes TykTechnologies#1833
Fixes #1833