Last active
August 6, 2021 11:38
-
-
Save percybolmer/649106f198b17b07b6ca178eaa1eed8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
) | |
func main() { | |
user := User{ | |
Name: "hello", | |
Email: "[email protected]", | |
} | |
WriteLog(user) | |
} | |
// WriteLog accepts any kind of objects and logs them | |
func WriteLog(data interface{}) { | |
switch result := data.(type) { | |
case User: | |
log.Println("Found user: ", result.Name) | |
default: | |
log.Println(data) | |
} | |
} | |
type User struct { | |
Name string | |
Email string | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment