...

/

Puzzle 11 Explanation: Go Log

Puzzle 11 Explanation: Go Log

Understand the concept of log in Go.

We'll cover the following...

Try it yourself

Try executing the code below to see the result.

Press + to interact
package main
import (
"fmt"
"time"
)
// Log is a log message
type Log struct {
Message string
time.Time
}
func main() {
ts := time.Date(2009, 11, 10, 0, 0, 0, 0, time.UTC)
log := Log{"Hello", ts}
fmt.Printf("%v\n", log)
}

Explanation

The %v verb will print all the struct fields.

Press + to interact
package main
import (
"fmt"
)
// Point is a 2D point
type Point struct {
X int
Y int
}
func main() {
p := Point{1, 2}
fmt.Printf("%v\n", p) // {1 2}
}

We’d expect the teaser code to print{Hello 2009-11-10 00:00:00 +0000 UTC}. ...