Test whether an input matches an entry in a map file.
This command returns a result that indicates whether an input matches an entry in a map file. This is useful for debugging maps.
Assume that you have a map file named /etc/hapee-1.8/routes.map with the following contents where the first column contains the keys and the second contains the values:
/cart/ cart_api /reviews/ reviews_api /products/ products_api /login/ login_api /chat/ chat_servers
In the HAProxy Enterprise configuration, we reference this map file on a
use_backend line with the
map_beg fetch method. This tells the load balancer to choose the backend from the map file by matching the beginning of the requested URL path with a key in the file:
frontend fe_main bind :80 use_backend %[path,map_beg(/etc/hapee-1.8/routes.map,be_servers)]
show mapscommand to list map files and their unique IDs. Here, the map file /etc/hapee-1.8/routes.map has an ID of 0:
$ echo "show map" | socat stdio tcp4-connect:127.0.0.1:9999 # id (file) description 0 (/etc/hapee-1.8/routes.map) pattern loaded from file '/etc/hapee-1.8/routes.map' used by map at file '/etc/hapee-1.8/hapee-lb.cfg' line 61
Pass that ID and an input string to
get mapto test whether the string would match any keys.
Below, we test whether the input string /reviews/war-and-peace/1 matches any keys:
$ echo "get map #0 /reviews/war-and-peace/1" | socat stdio tcp4-connect:127.0.0.1:9999 type=beg, case=sensitive, found=yes, idx=tree, key="/reviews/", value="reviews_api", type="str"
The result indicates that a match was found using the type beg, which means begins with. It matched the key /reviews/.
You can also pass the map file's path to get the same result:
$ echo "get map /etc/hapee-1.8/routes.map /reviews/war-and-peace/1" | socat stdio tcp4-connect:127.0.0.1:9999 type=beg, case=sensitive, found=yes, idx=tree, key="/reviews/", value="reviews_api", type="str"