36 lines
586 B
Go
36 lines
586 B
Go
package pods
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/containers/podman/v4/pkg/bindings"
|
|
)
|
|
|
|
var Socket = socketConnection()
|
|
|
|
func socketConnection() context.Context {
|
|
var uri string
|
|
if os.Getuid() != 0 {
|
|
uri = fmt.Sprintf("unix:///run/user/%d/podman/podman.sock", os.Getuid())
|
|
} else {
|
|
uri = "unix:///run/podman/podman.sock"
|
|
}
|
|
conn, err := bindings.NewConnection(context.Background(), uri)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
return conn
|
|
}
|
|
|
|
func TestPodman() {
|
|
_ = socketConnection()
|
|
}
|
|
|
|
// ConnectSocket()
|
|
func ConnectSocket() {
|
|
Socket = socketConnection()
|
|
}
|