func (cr CopyRewriter) copyGoSourceFile(ctx context.Context, destinationPath, sourcePath string) error {
	contents, err := ioutil.ReadFile(sourcePath)
	if err != nil {
		return err
	}
	var writer io.WriteCloser
	if cr.DryRun {
		writer = nopWriteCloser{ioutil.Discard}
	} else {
		writer, err = os.Create(destinationPath)
		if err != nil {
			return err
		}
		defer writer.Close()
	}
	if err = cr.rewriteGoAst(ctx, sourcePath, contents, writer); err != nil {
		return err
	}
	return cr.rewriteContents(ctx, destinationPath)
}
// copyGoSourceFile rewrites the imports for a golang file at a given path
copyGoSourceFile rewrites the imports for a golang file at a given path
// copyGoSourceFile rewrites the imports for a golang file at a given path
func (cr CopyRewriter) copyGoSourceFile(ctx context.Context, destinationPath, sourcePath string) error {
	contents, err := ioutil.ReadFile(sourcePath)
	if err != nil {
		return err
	}
	var writer io.WriteCloser
	if cr.DryRun {
		writer = nopWriteCloser{ioutil.Discard}
	} else {
		writer, err = os.Create(destinationPath)
		if err != nil {
			return err
		}
		defer writer.Close()
	}
	if err = cr.rewriteGoAst(ctx, sourcePath, contents, writer); err != nil {
		return err
	}
	return cr.rewriteContents(ctx, destinationPath)
}
func ( cr CopyRewriter ) copyGoSourceFile ( ctx context . Context , destinationPath , sourcePath string ) error { contents , err := ioutil . ReadFile ( sourcePath ) if err != nil { return err } var writer io . WriteCloser if cr . DryRun { writer = nopWriteCloser { ioutil . Discard } } else { writer , err = os . Create ( destinationPath ) if err != nil { return err } defer writer . Close ( ) } if err = cr . rewriteGoAst ( ctx , sourcePath , contents , writer ) ; err != nil { return err } return cr . rewriteContents ( ctx , destinationPath ) }
copyGoSourceFile rewrites the imports for a golang file at a given path
copyGoSourceFile rewrites the imports for a golang file at a given path