I have data which was previously serialized as fmt.Sprintf("%+v", d)
, d
being a struct
instance. Is there a way to scan it back? My naive attempt of using fmt.Sscanf()
below is failing (Go Playground).
package main
import (
"fmt"
)
type data struct {
f int
}
func main() {
x := data{1}
s := fmt.Sprintf("%+v", x)
var y data
n, err := fmt.Sscanf(s, "%+v", &y)
fmt.Printf("s=%s, n=%d, err=%+v, y=%+v
", s, n, err, y)
}
The output is:
s={f:1}, n=0, err=can't scan type: *main.data, y={f:0}
Is there a way to scan the struct back?