Skip to content

Instantly share code, notes, and snippets.

@pedrobertao
Created August 21, 2020 20:54
Show Gist options
  • Save pedrobertao/09bab1f37dd411d3af687fcedc6556ef to your computer and use it in GitHub Desktop.
Save pedrobertao/09bab1f37dd411d3af687fcedc6556ef to your computer and use it in GitHub Desktop.
package main
import "fmt"
type Person struct {
Name string
Surname string
}
func main() {
var joe Person
var maria *Person
var john = Person{
Name: "John",
Surname: "Smith",
}
if (joe == Person{}) {
fmt.Printf("Yes, it is empty: %v \n", joe)
}
/*
Output: Yes, it is empty: { }
*/
if maria == nil {
fmt.Printf("Yes, it is empty: %v \n", maria)
}
/*
Output: Yes, it is empty: <nil>
*/
if (john != Person{}) {
fmt.Printf("Not, it is not empty: %v \n", john)
}
/*
Output: Not, it is not empty: {John Smith}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment