Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: go/format: Use io.Reader and io.Writer interfaces as Source function parameters #56936

Closed
edebernis opened this issue Nov 25, 2022 · 2 comments
Labels
Milestone

Comments

@edebernis
Copy link

The current Source function accepts []byte array and returns another []byte array.

func Source(src []byte) ([]byte, error)

It would be nice to be able to rely on io.Reader and io.Writer interfaces to format sources.

func SourceStream(w io.Writer, r io.Reader) error

What do you think ?

Thanks !

@gopherbot gopherbot added this to the Proposal milestone Nov 25, 2022
@mvdan
Copy link
Member

mvdan commented Nov 25, 2022

You can already accomplish this via https://pkg.go.dev/go/parser#ParseFile and https://pkg.go.dev/go/format#Node, for example. I agree that the current APIs aren't perfect, but I'm not sure that more overlapping APIs will help.

@edebernis
Copy link
Author

Thanks ! A little more complex than expected but it does the job ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants