I installed the go package browser
.
Now the library does not work like I expect (issue) and I would like to add some fmt.Printf()
lines to the source of the package.
If I modify the file via goland, I get a warning that no backup file could be created:
Cannot save /home/guettli/go/pkg/mod/github.com/pkg/[email protected]/browser.go. Unable to create a backup file (browser.go~). The file left unchanged.
How to add print-statements to third party code in go/goland?
CodePudding user response:
How to add print-statements to third party code in [Go] [...]?
You cannot.
At least not in any simple way. You have to git (!) clone the module and replace
the module in your go.mod to point to your clone. Change the clone.
CodePudding user response:
Expanding on @Volker 's answer, you will need to have a local copy of the module to modify and use it. Here are the steps
- Clone the module repository
git clone https://github.com/pkg/browser.git
- If needed, checkout to a branch/tag
git checkout branch_name
- In the
go.mod
file of your module, add the following lines
replace (
github.com/pkg/browser => /path/where/cloned/browser
)
- Now you should be able to modify code in the cloned
browser
repo and use it in your module