github.com/haraldrudell/parl@v0.4.176/pfmt/no-recurse-v-print.go (about)

     1  /*
     2  © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  // Package pfmt provides an [fmt.Printf] %v function that does not use the [fmt.Stringer.String] method
     7  package pfmt
     8  
     9  import (
    10  	"fmt"
    11  	"strings"
    12  )
    13  
    14  type structWithPrivateFieldAny struct{ any }
    15  
    16  // NoRecurseVPrint returns the reflection string representation of value
    17  // without invoking the String method.
    18  func NoRecurseVPrint(value any) (s string) {
    19  	s = fmt.Sprint(structWithPrivateFieldAny{any: value})
    20  	s = strings.TrimPrefix(strings.TrimSuffix(s, "}"), "{")
    21  	return
    22  }