Skip to content

jussi-kalliokoski/go-prettyformat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages