How to make a chained call when the golang function has multiple return values?

The

golang function can have multiple return values. Can you specify the number of return values for chained calls, such as the following code:

package main
import "fmt"

func test()(s string,err error){
    return "hello",nil
}
func main(){
    fmt.Println("HelloWorld ",test().s)
}

I hope that after the test () function, ignore err and directly use the first argument, how can it not be called without defining a new variable?
both test () and test (). S are the same error:

. / tempCodeRunnerFile.go:8: multiple-value test () in single-value context

can"t multiple return values be called in chains?

Mar.06,2021

there should be no such operation to


according to your scene.

you can change the return value of test () to the same as the input parameter of fmt.Println, because this function originally supports multiple parameters.

as for multiple return values, I haven't tried chained calls either,


Don't have such a usage scenario. Obviously, it violates the convention
and does not conform to the code specification


.

Yes, multiple return values cannot be called in chains.

if the error returned by this test function is negligible, why do you return an error?


chain calls cannot be realized under multiple return values, thank you!


to be honest, this requirement is a little obsessive-compulsive. If you really have this need, you might as well encapsulate the multiple return values into a struct

.
Menu