Home >Backend Development >Golang >How to determine whether a golang structure is empty
How to determine whether the golang structure is empty
How to determine whether the golang structure is empty? To determine whether it has been initialized, the method is as follows:
You can use if objectA== (structname{}){ // your code } to determine.
The sample code is as follows:
package main import ( "fmt" "reflect" ) type A struct{ name string age int } func (a A) IsEmpty() bool { return reflect.DeepEqual(a, A{}) } func main() { var a A if a == (A{}) { // 括号不能去 fmt.Println("a == A{} empty") } if a.IsEmpty() { fmt.Println("reflect deep is empty") } }
For more programming tutorials, please pay attention to the PHP Chinese website!
The above is the detailed content of How to determine whether a golang structure is empty. For more information, please follow other related articles on the PHP Chinese website!