From 964a9e7f4542adde3bed2440cfff43cffc2d2466 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Tue, 27 Feb 2018 21:16:27 +0100 Subject: [PATCH] Add support for raw tags Raw tags add arbitrary route commands to the routing table. The current approach needs review but works. By prefixing a tag with 'fabio ' the following text will be added to the routing table. See #87 --- registry/consul/service.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/registry/consul/service.go b/registry/consul/service.go index 18bd4c38d..9ce8a1fa9 100644 --- a/registry/consul/service.go +++ b/registry/consul/service.go @@ -94,16 +94,24 @@ func serviceConfig(client *api.Client, name string, passing map[string]bool, tag continue } - // get all tags which do not have the tag prefix + // get all tags which do not have the tag prefix or the raw tag prefix + const rawPrefix = "fabio " var svctags []string for _, tag := range svc.ServiceTags { - if !strings.HasPrefix(tag, tagPrefix) { + if !strings.HasPrefix(tag, tagPrefix) && !strings.HasPrefix(tag, rawPrefix) { svctags = append(svctags, tag) } } // generate route commands for _, tag := range svc.ServiceTags { + // add raw tags as is + if strings.HasPrefix(tag, rawPrefix) { + tag = strings.TrimSpace(tag[len(rawPrefix):]) + config = append(config, tag) + continue + } + if route, opts, ok := parseURLPrefixTag(tag, tagPrefix, env); ok { name, addr, port := svc.ServiceName, svc.ServiceAddress, svc.ServicePort