MCPcopy
hub / github.com/fabiolb/fabio / delRoute

Method delRoute

route/table.go:285–349  ·  view source on GitHub ↗

delRoute removes one or more routes depending on the arguments. If service, prefix and target are provided then only this route is removed. Are only service and prefix provided then all routes for this service and prefix are removed. This removes all active instances of the service from the route. I

(d *RouteDef)

Source from the content-addressed store, hash-verified

283// provided then all routes for this service are removed. The service
284// will no longer receive traffic. Routes with no targets are removed.
285func (t Table) delRoute(d *RouteDef) error {
286 switch {
287 case len(d.Tags) > 0:
288 for _, routes := range t {
289 for _, r := range routes {
290 r.filter(func(tg *Target) bool {
291 return (d.Service == "" || tg.Service == d.Service) && contains(tg.Tags, d.Tags)
292 })
293 }
294 }
295
296 case d.Src == "" && d.Dst == "":
297 for _, routes := range t {
298 for _, r := range routes {
299 r.filter(func(tg *Target) bool {
300 return tg.Service == d.Service
301 })
302 }
303 }
304
305 case d.Dst == "":
306 r := t.route(hostpath(d.Src))
307 if r == nil {
308 return nil
309 }
310 r.filter(func(tg *Target) bool {
311 return tg.Service == d.Service
312 })
313
314 default:
315 targetURL, err := url.Parse(d.Dst)
316 if err != nil {
317 return fmt.Errorf("route: invalid target. %s", err)
318 }
319
320 r := t.route(hostpath(d.Src))
321 if r == nil {
322 return nil
323 }
324 r.filter(func(tg *Target) bool {
325 return tg.Service == d.Service && tg.URL.String() == targetURL.String()
326 })
327 }
328
329 // remove all routes without targets
330 for host, routes := range t {
331 var clone Routes
332 for _, r := range routes {
333 if len(r.Targets) == 0 {
334 continue
335 }
336 clone = append(clone, r)
337 }
338 t[host] = clone
339 }
340
341 // remove all hosts without routes
342 for host, routes := range t {

Callers 2

NewTableFunction · 0.80
NewTableCustomFunction · 0.80

Calls 5

routeMethod · 0.95
containsFunction · 0.85
hostpathFunction · 0.85
filterMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected