Skip to content
Pretty-print Go data structures as valid Go code
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
go.mod
readme.md
repr.go
repr_test.go

readme.md

Overview

Prints Go data structures as syntactically valid Go code. Useful for code generation. The name "repr" stands for "representation" and alludes to the Python function with the same name.

Solves a problem unaddressed by https://github.com/davecgh/go-spew/spew and directly competes with https://github.com/shurcooL/go-goon.

See godoc at https://godoc.org/github.com/mitranim/repr.

Example

import "github.com/mitranim/repr"

type Data struct {
  Number int
  String string
  List   []int
}

fmt.Println(repr.String(Data{
  Number: 123,
  String: "hello world!",
  List:   []int{10, 20, 30},
}))

/*
Data{
  Number: 123,
  String: "hello world!",
  List: []int{10, 20, 30},
}
*/

See the API documentation at https://godoc.org/github.com/mitranim/repr.

License

https://en.wikipedia.org/wiki/WTFPL

Misc

I'm receptive to suggestions. If this package almost satisfies you but needs changes, open an issue or chat me up. Contacts: https://mitranim.com/#contacts

You can’t perform that action at this time.