github.com/mitranim/gg@v0.1.17/grepr/readme.md (about)

     1  Missing feature of the standard library: printing arbitrary inputs as Go code, with proper spacing and support for multi-line output with indentation. The name "repr" stands for "representation" and alludes to the Python function with the same name.
     2  
     3  API doc: https://pkg.go.dev/github.com/mitranim/gg/grepr
     4  
     5  Example:
     6  
     7  ```go
     8  package mock
     9  
    10  import (
    11    "fmt"
    12  
    13    "github.com/mitranim/gg"
    14    "github.com/mitranim/gg/grepr"
    15  )
    16  
    17  type Outer struct {
    18    OuterId   int
    19    OuterName string
    20    Embed
    21    Inner *Inner
    22  }
    23  
    24  type Embed struct {
    25    EmbedId   int
    26    EmbedName string
    27  }
    28  
    29  type Inner struct {
    30    InnerId   *int
    31    InnerName *string
    32  }
    33  
    34  func main() {
    35    fmt.Println(grepr.String(Outer{
    36      OuterName: `outer`,
    37      Embed:     Embed{EmbedId: 20},
    38      Inner:     &Inner{
    39        InnerId:   gg.Ptr(30),
    40        InnerName: gg.Ptr(`inner`),
    41      },
    42    }))
    43  
    44    /**
    45    mock.Outer{
    46      OuterName: `outer`,
    47      Embed: mock.Embed{EmbedId: 20},
    48      Inner: &mock.Inner{
    49        InnerId: gg.Ptr(30),
    50        InnerName: gg.Ptr(`inner`),
    51      },
    52    }
    53    */
    54  }
    55  ```