Please excuse me for not knowing the proper name for the following syntax
type Foo struct{}
func (Foo) One() (int, error) {
// Logic...
}
func (Foo) Two() (int, error) {
// Logic
}
I am using the empty struct Foo
as a way to group some of the similar functions. So when I call the function One
, I will use the following syntax:
fooNum, err := Foo{}.One()
It works perfectly fine until I try to do the following:
if fooNum, err := Foo{}.One(); err == nil {
// Logic...
}
I get syntax error: unexpected newline, expecting comma or }
. I wonder why is this the case? Is there a bigger reason behind this error? Am I doing something that is discouraged by general Go style?