Last active
July 25, 2019 09:39
-
-
Save joseluisq/6bcc862145be70e305aa9b7ba8c232c7 to your computer and use it in GitHub Desktop.
Simple Go dump function for struct slices variables (WIP) https://play.golang.org/p/KxpMJdFSDkI
This file contains 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 ( | |
"fmt" | |
) | |
type ( | |
Author struct { | |
Name string | |
Email string | |
Status bool | |
} | |
) | |
func dump(authors []Author, msg string) { | |
fmt.Printf("Dumping variables\nType: %T\nMessage: %s\n", authors, msg) | |
fmt.Println("---------------") | |
for i, author := range authors { | |
fmt.Printf( | |
"%o. | %s %v | %s %v | %s %v | \n", | |
i, "Name:", author.Name, "Email:", author.Email, "Status:", author.Status, | |
) | |
} | |
fmt.Println("") | |
} | |
func main() { | |
var authors = []Author{ | |
{Name: "Jose Quintana", Email: "jq@system.local", Status: true}, | |
{Name: "Tux Linux", Email: "tl@system.local", Status: false}, | |
} | |
dump(authors, "Optional description...") | |
// Output: | |
// | |
// Dumping variables | |
// Type: []main.Author | |
// Message: Optional description... | |
// --------------- | |
// 0. | Name: Jose Quintana | Email: jq@system.local | Status: true | | |
// 1. | Name: Tux Linux | Email: tl@system.local | Status: false | | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment