Connect to the P4 Server
The following is an example of how to connect to the P4 Server using P4 API for Go.
Copy
import (
"fmt"
"p4"
)
p4api := p4.New()
defer p4api.Close()
// Set connection details
p4api.SetPort("perforce:1666")
p4api.SetUser("username")
p4api.SetPassword("password")
// Connect to the P4 server
connected, err := p4api.Connect()
if err != nil {
fmt.Println("Error connecting to P4 server:", err)
return
}
if connected {
fmt.Println("Connected to P4 server.")
}
// Run login
res, err := p4api.RunLogin()
if err != nil {
fmt.Println("Error running login:", err)
return
}
fmt.Println("Login response:", res)