Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xgfone/go-linux-namespace

The operation about linux namespace.
https://github.com/xgfone/go-linux-namespace

linux linux-namespace namespace

Last synced: about 1 month ago
JSON representation

The operation about linux namespace.

Awesome Lists containing this project

README

        

# Linux Namespace [![Build Status](https://github.com/xgfone/go-linux-namespace/actions/workflows/go.yml/badge.svg)](https://github.com/xgfone/go-linux-namespace/actions/workflows/go.yml) [![GoDoc](https://pkg.go.dev/badge/github.com/xgfone/go-namespace)](https://pkg.go.dev/github.com/xgfone/go-namespace) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](https://raw.githubusercontent.com/xgfone/go-namespace/master/LICENSE)

The operation about linux namespace. Support `Go1.7+`.

## Installation
```shell
$ go get -u github.com/xgfone/go-linux-namespace
```

## Example
```go
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
}
}
```