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

example with multiple return types #107

Closed
technicallyty opened this issue Jun 5, 2023 · 5 comments
Closed

example with multiple return types #107

technicallyty opened this issue Jun 5, 2023 · 5 comments

Comments

@technicallyty
Copy link

was generating code that has multiple return types, but wasn't able to find a way to write that cleanly. currently what i'm doing is (and im not proud of this):

		g.file.Func().Id("Unmarshal" + g.abiTypeStructName(obj.name)).
			Params(jen.Id("bz").List().Byte()).
			Id("(").
			Id(obj.name + ",").
			Id("error").
			Id(")").
			Block()

any help appreciated 🤟🏻

@dave
Copy link
Owner

dave commented Jun 6, 2023

What is the code you're trying to return?

@technicallyty
Copy link
Author

func Foo(bz []byte) (SomeStruct, error)

@dave
Copy link
Owner

dave commented Jun 6, 2023

Use https://github.com/dave/jennifer#params for that:

g.file.Func().Id("Unmarshal" + g.abiTypeStructName(obj.name)).
			Params(jen.Id("bz").List().Byte()).
			Params(jen.Id(obj.name), jen.Id("error")).
			Block()

@dave
Copy link
Owner

dave commented Jun 6, 2023

lol just realised who I'm talking to 😂 hey Tyler!

@technicallyty
Copy link
Author

ah idk why i didnt think to just use params again lol. Thanks Dave!

hahah hello! hope you've been enjoying your travels 🤝

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

No branches or pull requests

2 participants