jussi-kalliokoski / go-prettyformat

Stringify go values

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status GoDoc

go-prettyformat

A go package for stringifying go values, similar to pretty-format for JavaScript.

Supports pretty much all go types except arbitrary pointer values, functions, interface instances and channels.

The primary use case for this package is to support snapshot testing of data structures.

Installation

go get github.com/jussi-kalliokoski/go-prettyformat

Example

import (
    "github.com/jussi-kalliokoski/go-prettyformat"
    "fmt"
)

func main() {
    type foo struct {
        Foo interface{}
    }

    str, err := prettyformat.Format(
        [1]foo{
            foo{
                Foo: []*foo{
                    &foo{
                        Foo: map[string]interface{}{
                            "foo": foo{
                                Foo: "123",
                            },
                        },
                    },
                },
            },
        },
    )

    if err != nil {
        panic(err)
    }

    fmt.Println(str)
    // [1]foo{
    //   foo{
    //     Foo: []*foo{
    //       &foo{
    //         Foo: map[string]interface{}{
    //           "foo": foo{
    //             Foo: (string)"123",
    //           },
    //         },
    //       },
    //     },
    //   },
    // }
}

License

The MIT License (MIT) - see LICENSE file for more details.

About

Stringify go values

License:MIT License


Languages

Language:Go 100.0%