Skip to content

Go bindings for radix tree library for fast subnet (IPv4 and IPv6) lookups

License

Notifications You must be signed in to change notification settings

thekvs/go-net-radix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

Go programming language (http://golang.org/) bindings for radix tree library for fast subnet (both IPv4 and IPv6) lookups.

Installing

$ go get github.com/thekvs/go-net-radix

After this command go-net-radix library is ready to use and will be located in:

$GOROOT/src/pkg/github.com/thekvs/go-net-radix

Basic usage example

package main

import (
        "github.com/thekvs/go-net-radix"

        "fmt"
        "log"
)

func main() {
        rtree, err := netradix.NewNetRadixTree()
        if err != nil {
                panic(err)
        }
        defer rtree.Close()

        if err = rtree.Add("217.72.192.0/20", "UDATA1"); err != nil {
                log.Fatal(err)
        }

        if err = rtree.Add("2001:220::/35", "UDATA2"); err != nil {
                log.Fatal(err)
        }

        var found bool
        var udata string

        found, udata, err = rtree.SearchBest("217.72.192.2")
        if err != nil {
                log.Fatal(err)
        }
        if found {
                fmt.Printf("found: %v\n", udata)
        }

        found, udata, err = rtree.SearchBest("2001:220::")
        if err != nil {
                log.Fatal(err)
        }
        if found {
                fmt.Printf("found: %v\n", udata)
        }

        if err = rtree.Remove("217.72.192.0/20"); err != nil {
                log.Fatal(err)
        }
}

Documentation

GoDoc

Licensing

All source code included in this distribution is covered by the MIT License found in the LICENSE file, unless specifically stated otherwise within each file.

About

Go bindings for radix tree library for fast subnet (IPv4 and IPv6) lookups

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published