runtime: goroutine stack exceeds 1000000000-byte limit, fatal error: stack overflow on printing a nested struct

后端 未结 1 1844
太阳男子
太阳男子 2021-01-12 11:36

I have a nested struct.

type ConfigOne struct {
    // Daemon section from config file.
    Daemon daemon
}
type daemon struct {
    Loglevel int
    Logfile         


        
相关标签:
1条回答
  • 2021-01-12 12:14

    The %v and %+v formats use the value of String() if the type implements it. Therefore, using %+v on a type within the String() function for that type causes infinite recursion. Instead of using %+v in the String() function, you'll have to construct your own string, showing the contents of the structure in whatever way you see fit.

    0 讨论(0)
提交回复
热议问题