Consul template and services sort order

382 views
Skip to first unread message

Jeffrey Earl

unread,
Jun 14, 2016, 6:03:26 PM6/14/16
to Consul
Hi, I'm using consul template to generate HAProxy mappings and see that the services call gives me my services in alphabetical order. I'm trying to reverse that order to guard against an edge case where services may start with the same string. For example, if I have services xyz and xyz123, my front end paths will generate in order:
xyz
xyz123

If I make a request for xyz123, HAProxy will match xyz first. This is because the way HAProxy uses essentially "starts with" to route the request based on the start of the service URI. I have not been able to figure out a way to change the order of the range using either standard golang template functionality or consul template functions. Am I missing something simple, or would this need to be something added to the functions that consul template add to the func map?

Cheers,
Jeff

behnam saberi

unread,
Oct 6, 2019, 3:19:38 AM10/6/19
to Consul
Hi Jeffrey
I have the same problem. Have you found the solution?

John Eikenberry

unread,
Oct 7, 2019, 3:39:01 PM10/7/19
to consu...@googlegroups.com
Hey Jeff, Behnam,

The only way to control sorting order in templates at this moment is to use maps. All maps are sorted by keys when iterated over, so if you can arrange your entries in a  scratch.MapSet with the keys set such that when sorted they'd order them the way you'd like... you can sort things that way.


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/consul/issues
Community chat: https://gitter.im/hashicorp-consul/Lobby
---
You received this message because you are subscribed to the Google Groups "Consul" group.
To unsubscribe from this group and stop receiving emails from it, send an email to consul-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/consul-tool/be0ce2b2-b0dd-48ad-922c-86d46746c10f%40googlegroups.com.


--
John Eikenberry <jeike...@hashicorp.com>
________________________________________________________________________
"Perfection is attained, not when no more can be added, but when no more
 can be removed." -- Antoine de Saint-Exupery
Reply all
Reply to author
Forward
0 new messages