'How to add lines after a certain pattern in go file?

There are many go files where I need to add the same set of lines after an error has been found and it is being returned like the example given below. How can I automate this process?

if err != nil {
    // add few lines here
    return err
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source