We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi
Im trying to create a function that has a receiver of a struct type. For the life of me I cant work out how to do this?
Is it possible or not an implemented feature?
for example generate the code
type Foo struct{} func (f Foo) Print(){ fmt.Printf("%v\n", f) }
Thanks
The text was updated successfully, but these errors were encountered:
Like this?
func ExampleStructReceiver() { f := NewFile("main") f.Type().Id("Foo").Struct() f.Func().Params(Id("f").Id("Foo")).Id("Print").Params().Block( Qual("fmt", "Printf").Call(Lit("%v\n"), Id("f")), ) fmt.Printf("%#v", f) // Output: // package main // // import "fmt" // // type Foo struct{} // // func (f Foo) Print() { // fmt.Printf("%v\n", f) // } }
Sorry, something went wrong.
Yea exactly that thanks, I acutally figured that out just after I asked and then lost internet connection and you beat me to closing it.
No branches or pull requests
Hi
Im trying to create a function that has a receiver of a struct type. For the life of me I cant work out how to do this?
Is it possible or not an implemented feature?
for example generate the code
Thanks
The text was updated successfully, but these errors were encountered: