When the Interface{} data return shows nil,nil, why s.IsNil() function returns bool value as false when expected is true.
I tried with different non-nil values but the empty interface is a concept I don’t understand.
Below is the code
package main
import "fmt"
import "reflect"
type Auth struct {
a, b interface{}
}
func main() {
//p1 := Auth{"test1", "pswd1"}
// p2 := Auth{123, "pswd2"}
p1 := Auth{}
callFunc(p1)
}
func callFunc(a ...interface{}) Auth {
var a1 Auth
s := reflect.ValueOf(a)
fmt.Println(a1)
if (s.IsNil()) {
fmt.Println("YES")
fmt.Println(a1)
a1 = Auth{"NewData", "test2"}
// return a1
} else {
fmt.Println(s.IsNil())
fmt.Println(s)
return a1
}
return a1
}
Output is
false
[{ }]