Add and submit files to Perforce
The following is an example of how to add and submit files to Perforce using P4 API for Go.
Copy
// Add a file to Perforce
filePath := "example.txt"
err := os.WriteFile(filePath, []byte("This is a test file."), 0644)
if err != nil {
fmt.Println("Error creating file:", err)
return
}
_, err = p4api.Run("add", filePath)
if err != nil {
fmt.Println("Error in adding files:", err)
return
}
// Submit the file
changeSpec, err := p4api.RunFetch("change")
if err != nil {
fmt.Println("Error fetching change spec:", err)
return
}
changeSpec["Description"] = "Adding a new file"
_, err = p4api.RunSubmit(changeSpec)
if err != nil {
fmt.Println("Error submitting change:", err)
} else {
fmt.Println("File submitted successfully.")
}