inettree

package
v2.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2022 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Package inettree implements the tree.Interface for inet.Block

Example (Usage)
package main

import (
	"fmt"

	"github.com/gaissmai/go-inet/v2/inet"
	"github.com/gaissmai/go-inet/v2/inettree"
	"github.com/gaissmai/go-inet/v2/tree"
)

var iana = map[string]string{
	"::/8":     "Reserved by IETF     [RFC3513][RFC4291]",
	"100::/8":  "Reserved by IETF     [RFC3513][RFC4291]",
	"200::/7":  "Reserved by IETF     [RFC4048]",
	"400::/6":  "Reserved by IETF     [RFC3513][RFC4291]",
	"800::/5":  "Reserved by IETF     [RFC3513][RFC4291]",
	"1000::/4": "Reserved by IETF     [RFC3513][RFC4291]",
	"2000::/3": "Global Unicast       [RFC3513][RFC4291]",
	"2000::/4": "",
	"3000::/4": "FREE",
	"4000::/3": "Reserved by IETF     [RFC3513][RFC4291]",
	"6000::/3": "Reserved by IETF     [RFC3513][RFC4291]",

	// force duplicate error
	"2000::0000/3": "Global Unicast       [RFC3513][RFC4291]",
}

func main() {
	bs := make([]tree.Interface, 0, len(iana))

	for k, text := range iana {
		block, err := inet.ParseBlock(k)
		if err != nil {
			panic(err)
		}
		if text != "" {
			text = block.String() + " ... " + text
		}
		bs = append(bs, inettree.Item{block, text})
	}

	t, err := tree.New(bs)
	if err != nil {
		fmt.Println("ERROR:", err)
		fmt.Printf("dups: %v\n\n", t.Duplicates())
	}

	fmt.Println(t)

}
Output:

ERROR: some items are duplicate
dups: [2000::/3 ... Global Unicast       [RFC3513][RFC4291]]

▼
├─ ::/8 ... Reserved by IETF     [RFC3513][RFC4291]
├─ 100::/8 ... Reserved by IETF     [RFC3513][RFC4291]
├─ 200::/7 ... Reserved by IETF     [RFC4048]
├─ 400::/6 ... Reserved by IETF     [RFC3513][RFC4291]
├─ 800::/5 ... Reserved by IETF     [RFC3513][RFC4291]
├─ 1000::/4 ... Reserved by IETF     [RFC3513][RFC4291]
├─ 2000::/3 ... Global Unicast       [RFC3513][RFC4291]
│  ├─ 2000::/4
│  └─ 3000::/4 ... FREE
├─ 4000::/3 ... Reserved by IETF     [RFC3513][RFC4291]
└─ 6000::/3 ... Reserved by IETF     [RFC3513][RFC4291]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item struct {
	// the augmented Block
	inet.Block

	// augment Block with additional text, see example
	Text string
}

Item augments inet.Block, implementing the tree.Interface

func (Item) Covers

func (a Item) Covers(i tree.Interface) bool

Covers implements the tree.Interface for Item

func (Item) Equals added in v2.0.4

func (a Item) Equals(i tree.Interface) bool

Equals implements the tree.Interface for Item

func (Item) Less

func (a Item) Less(i tree.Interface) bool

Less implements the tree.Interface for Item

func (Item) String

func (a Item) String() string

String implements the tree.Interface for Item

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL