The operation about linux namespace. Support Go1.7+
.
$ go get -u github.com/xgfone/go-linux-namespace
package main
import (
"fmt"
"github.com/xgfone/go-linux-namespace"
)
func main() {
ns := NewNameSpace("name")
// Ensure that the namespace exists.
if exist, err := ns.IsExist(); err != nil {
fmt.Println(err)
return
} else if !exist {
if err := ns.Create(); err != nil {
fmt.Println(err)
return
}
}
// Execute the command in the namespace.
if output, err := ns.Exec("ip", "a"); err != nil {
fmt.Println(err)
} else {
fmt.Println(output)
}
// Delete the namespace.
if err := ns.Delete(); err != nil {
fmt.Println(err)
return
}
}