You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zk/internal/core/util.go

29 lines
583 B
Go

package core
// lazyStringer implements Stringer and wait for String() to be called the first
// time before computing its value.
type lazyStringer struct {
value *string
render func() string
}
func newLazyStringer(render func() string) *lazyStringer {
return &lazyStringer{render: render}
}
// String implements Stringer.
func (s *lazyStringer) String() string {
if s == nil {
return ""
}
if s.value == nil {
str := s.render()
s.value = &str
}
return *s.value
}
func (s *lazyStringer) MarshalJSON() ([]byte, error) {
return []byte(`"` + s.String() + `"`), nil
}