Hi,
I'm tidying up some code and I think this would be a great use for gofmt's rewrite capabilities, but I can't make it work. I have some code where error checking is missing.
In the code every instance of Set returns an error value that is not checked, so I assumed I could write:
gofmt -w -r 'a.Set(b,c) -> err:=a.Set(b,c)\nif err != nil{log.Fatal("Set Error",err)}'
and (for example) this would change:
x.Set(bob,fred)
to:
err := x.Set(bob,fred)
if err != nil{log.Fatal("Set Error",err)}
(Actual error handling removed for simplicity of example)
Before I crack out sed or perl, any suggestions for if this is possible the "correct" way?
In a follow up question, I've come across go IDEs which allow you to do things like automatically rename handler receivers to be consistent across a type. Unfortunately it doesn't seem to be possible to do this with gofmt out of the box, as rewrite rules can't target specific types that I know of. Is this actually possible?
I guess a further question is, while I have found some examples of gofmt rules, they seem to be quite thin on the ground, is anyone aware of a good collection of examples?
Regards
Chris