Categorygithub.com/derekhjray/namespace
modulepackage
0.1.9
Repository: https://github.com/derekhjray/namespace.git
Documentation: pkg.go.dev

# README

Namespace

A namespace executor help library, used to execute task in specified linux namespaces

Example

package main

import (
	"bytes"
	"log"
	"os/exec"
	"context"
	"github.com/derekhjray/namespace"
)

func ipLink(_ ...interface{}) error {
	var (
		stdout bytes.Buffer
	)

	cmd := exec.CommandContext(context.TODO(), "ip", "link")
	cmd.Stdout = &stdout
	if err := cmd.Run(); err != nil {
		return nil
	}

	log.Println(stdout.String())
	return nil
}

func main() {
	ns, err := namespace.New(namespace.Types(NET), namespace.Pid(2398))
	if err != nil {
		log.Println(err)
		return
	}

	err = ns.Execute(ipLink)
	if err != nil {
		log.Println(err)
		return
	}

	if err = ipLink(); err != nil {
		log.Println(err)
	}
}

# Packages

No description provided by the author
No description provided by the author

# Functions

New creates a new Namespace instance.
Pid specify which namespaces of process to use.
Prefix specify prefix of directory /proc, which is useful while using this package in container that has bind host /proc into container.
Types specify namespace types while creating Namespace instance, supports NET, UTS, IPC, USER, PID and NET.

# Variables

No description provided by the author

# Structs

No description provided by the author

# Type aliases

No description provided by the author