Skip to content

Instantly share code, notes, and snippets.

@joseluisq
Last active July 25, 2019 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joseluisq/6bcc862145be70e305aa9b7ba8c232c7 to your computer and use it in GitHub Desktop.
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
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