go死循环坑

43 阅读1分钟
type IDPercenage int32

func (p IDPercenage) String() String {
    return fmt.Sprintf("%v",p)
}

当String函数被调用时,死循环就出现了,因为%V会默认调用该结构体的String()函数,从而死循环,程序已启动就栈溢出。。。。。 解决方法:

type IDPercenage int32

func (p IDPercenage) String() String {
    return fmt.Sprintf("%d",int32(p))
}