Created
August 4, 2016 11:07
-
-
Save gkleiman/d87c6e39c8fd47d8de4ec81c874f6f96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"net/http" | |
"os" | |
"syscall" | |
"github.com/opencontainers/runc/libcontainer/system" | |
) | |
func doNetns(nsPath string) error { | |
ns, err := os.Open(nsPath) | |
if err != nil { | |
return err | |
} | |
return system.Setns(ns.Fd(), syscall.CLONE_NEWNET) | |
} | |
func doGet(port string) { | |
response, err := http.Get("http://localhost:" + port) | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "%s\n", err) | |
} else { | |
defer response.Body.Close() | |
_, err := io.Copy(os.Stderr, response.Body) | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "%s\n", err) | |
} | |
} | |
} | |
func main() { | |
doNetns(os.Args[1]) | |
doGet(os.Args[2]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment