diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-03-11 03:27:34 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-03-11 03:27:34 +0900 |
commit | 89acf5c8a4603b1f3b38f182c35e69b5847ddd1f (patch) | |
tree | 97ca76b454ee37e39ab516bf5f035328580db8bd | |
parent | bcfc808df4f6bc5551fc4b760630d30748e89d43 (diff) |
cli: refactoring
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | gobgp/cmd/global.go | 51 |
1 files changed, 16 insertions, 35 deletions
diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go index 77e9c81c..317ff0ee 100644 --- a/gobgp/cmd/global.go +++ b/gobgp/cmd/global.go @@ -542,48 +542,29 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*api.Path, error) { Pattrs: make([][]byte, 0), } - args, origin, err := extractOrigin(args) - if err != nil { - return nil, err - } - attrs = append(attrs, origin) - - args, nexthop, err := extractNexthop(rf, args) - if err != nil { - return nil, err - } - - args, med, err := extractMed(args) - if err != nil { - return nil, err - } - if med != nil { - attrs = append(attrs, med) - } - - args, localPref, err := extractLocalPref(args) - if err != nil { - return nil, err - } - if localPref != nil { - attrs = append(attrs, localPref) + fns := []func([]string) ([]string, bgp.PathAttributeInterface, error){ + extractOrigin, + extractMed, + extractLocalPref, + extractCommunity, + extractAigp, } - args, community, err := extractCommunity(args) - if err != nil { - return nil, err - } - if community != nil { - attrs = append(attrs, community) + for _, fn := range fns { + var a bgp.PathAttributeInterface + args, a, err = fn(args) + if err != nil { + return nil, err + } + if a != nil { + attrs = append(attrs, a) + } } - args, aigp, err := extractAigp(args) + args, nexthop, err := extractNexthop(rf, args) if err != nil { return nil, err } - if aigp != nil { - attrs = append(attrs, aigp) - } switch rf { case bgp.RF_IPv4_UC, bgp.RF_IPv6_UC: |