Skip to content
This repository has been archived by the owner on Mar 20, 2020. It is now read-only.

Commit

Permalink
Add examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
klauspost committed Feb 20, 2015
1 parent 4d69e2a commit 1309774
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 0 deletions.
20 changes: 20 additions & 0 deletions examples/opendb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// +build ignore

package main

// To run, execute: go run opendb.go

import (
"github.com/klauspost/oui"
)

// Example of opening a database
func main() {
// Load the content from "sampledb.txt" into a static database
db, err := oui.OpenStaticFile("sampledb.txt")
if err != nil {
panic(err)
}

oui.PrintDb(db)
}
29 changes: 29 additions & 0 deletions examples/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// +build ignore

package main

// To run, execute: go run query.go

import (
"fmt"
"github.com/klauspost/oui"
)

// Example of querying a database
func main() {
// Load the content from "sampledb.txt" into a static database
db, err := oui.OpenStaticFile("sampledb.txt")
if err != nil {
panic(err)
}

// Query on text string
entry, err := db.Query("00-60-93-98-02-01")
if err == oui.ErrNotFound {
fmt.Println("Not found")
} else if err != nil {
panic(err)
} else {
fmt.Println(entry.String())
}
}
32 changes: 32 additions & 0 deletions examples/querybytes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// +build ignore

package main

// To run, execute: go run querybytes.go

import (
"fmt"
"github.com/klauspost/oui"
)

// Example of looking up with byte values
func main() {
// Load the content from "sampledb.txt" into a static database
db, err := oui.OpenStaticFile("sampledb.txt")
if err != nil {
panic(err)
}

// We create a hardware address with the values we would like to look up:
hw := oui.HardwareAddr{0x00, 0x60, 0x92}

// Now we look up
entry, err := db.LookUp(hw)
if err == oui.ErrNotFound {
fmt.Println("Not found")
} else if err != nil {
panic(err)
} else {
fmt.Println(entry.String())
}
}
24 changes: 24 additions & 0 deletions examples/sampledb2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Generated: Thu, 29 Jan 2015 00:39:43 -0500

OUI/MA-L Organization
company_id Organization
Address

00-60-92 (hex) MICRO/SYS, INC.
006092 (base 16) MICRO/SYS, INC.
3447 OCEAN VIEW BLVD.
GLENDALE CA 91208
UNITED STATES

00-60-93 (hex) VARIAN
006093 (base 16) VARIAN
2700 MITCHELL DR.
WALNUT GREEK CA 94598
UNITED STATES

00-60-94 (hex) IBM Corp - UPDATED
006094 (base 16) IBM Corp
3039 E Cornwallis Road
PO BOX 12195
Research Triangle Park NC 27709-2195
UNITED STATES
39 changes: 39 additions & 0 deletions examples/updatedb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// +build ignore

package main

// To run, execute: go run updatedb.go

import (
"fmt"
"github.com/klauspost/oui"
)

// Example of opening a database and updating it with new content.
func main() {
// Load the content from "sampledb.txt" into a dynamic database
db, err := oui.OpenFile("sampledb.txt")
if err != nil {
panic(err)
}

// Get an entry
entry, err := db.Query("00-60-94")
if err != nil {
panic(err)
}
fmt.Println("\n*** First Lookup:\n" + entry.String())

// Update the database
err = oui.UpdateFile(db, "sampledb2.txt")
if err != nil {
panic(err)
}

// Get an entry
entry, err = db.Query("00-60-94")
if err != nil {
panic(err)
}
fmt.Println("\n*** Second Lookup:\n" + entry.String())
}

0 comments on commit 1309774

Please sign in to comment.