Documentation
¶
Overview ¶
Package route implements basic api to interact with system IP tables.
Add and Delete operations are implemented for gateway/interface addresses.
Example (GatewayIP) ¶
package main
import (
"log"
"net"
"github.com/goxray/core/network/route"
)
func main() {
routes := []*route.Addr{
route.MustParseAddr("93.184.215.14"), // example.com IP address
}
opts := route.Opts{Gateway: net.IP{192, 0, 0, 1}, Routes: routes}
// Route to 192.0.0.1
if err := route.Add(opts); err != nil {
log.Fatal(err)
}
// Remove route from the table
if err := route.Delete(opts); err != nil {
log.Fatal(err)
}
}
Example (NetworkInterface) ¶
package main
import (
"log"
"github.com/goxray/core/network/route"
)
func main() {
routes := []*route.Addr{
route.MustParseAddr("93.184.215.14"), // example.com IP address
}
opts := route.Opts{IfName: "en0", Routes: routes}
// Route to default Mac OS interface `en0`
if err := route.Add(opts); err != nil {
log.Fatal(err)
}
// Remove route from the table
if err := route.Delete(opts); err != nil {
log.Fatal(err)
}
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Addr ¶
Addr represents IP and Port.
func MustParseAddr ¶
MustParseAddr is the same as ParseAddr but panics on errors.
type Opts ¶
Opts represent route action options. You must specify either IfName or Gateway, specifying both will trigger Validate error.
Click to show internal directories.
Click to hide internal directories.