sanity-io/litter hiện có 1.7k sao trên GitHub, viết chủ yếu bằng Go. Litter is a pretty printer library for Go data structures to aid in debugging and testing.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Litter is a pretty printer library for Go data structures to aid in debugging and testing.
Litter is provided by
Sanity: The Headless CMS Construction Kit
Litter named for the fact that it outputs literals, which you litter your output with. As a side benefit, all Litter output is syntactically correct Go. You can use Litter to emit data during debug, and it's also really nice for "snapshot data" in unit tests, since it produces consistent, sorted output. Litter was inspired by Spew, but focuses on terseness and readability.
Basic example
This:
type Person struct {
Name string
Age int
Parent *Person
}
litter.Dump(Person{
Name: "Bob",
Age: 20,
Parent: &Person{
Name: "Jane",
Age: 50,
},
})
Litter is a great alternative to JSON or YAML for providing "snapshots" or example data. For example:
func TestSearch(t *testing.T) {
result := DoSearch()
actual := litterOpts.Sdump(result)
expected, err := ioutil.ReadFile("testdata.txt")
if err != nil {
// First run, write test data since it doesn't exist
if !os.IsNotExist(err) {
t.Error(err)
}
ioutil.Write("testdata.txt", actual, 0644)
actual = expected
}
if expected != actual {
t.Errorf("Expected %s, got %s", expected, actual)
}
}
The first run will use Litter to write the data to testdata.txt. On subsequent runs, the test will compare the data. Since Litter always provides a consistent view of a value, you can compare the strings directly.
Circular references
Litter detects circular references or aliasing, and will replace additional references to the same object with aliases. For example:
Add this import line to the file you're working in:
import "github.com/sanity-io/litter"
To dump a variable with full newlines, indentation, type, and aliasing information, use Dump or Sdump:
litter.Dump(myVar1)
str := litter.Sdump(myVar1)
litter.Dump(value, ...)
Dumps the data structure to STDOUT.
litter.Sdump(value, ...)
Returns the dump as a string
Configuration
You can configure litter globally by modifying the default litter.Config
// Strip all package names from types
litter.Config.StripPackageNames = true
// Hide private struct fields from dumped structs
litter.Config.HidePrivateFields = true
// Hide fields matched with given regexp if it is not nil. It is set up to hide fields generate with protoc-gen-go
litter.Config.FieldExclusions = regexp.MustCompile(`^(XXX_.*)$`)
// Sets a "home" package. The package name will be stripped from all its types
litter.Config.HomePackage = "mypackage"
// Sets separator used when multiple arguments are passed to Dump() or Sdump().
litter.Config.Separator = "\n"
// Use compact output: strip newlines and other unnecessary whitespace
litter.Config.Compact = true
// Prevents duplicate pointers from being replaced by placeholder variable names (except in necessary, in the case
// of circular references)
litter.Config.DisablePointerReplacement = true
litter.Options
Allows you to configure a local configuration of litter to allow for proper compartmentalization of state at the expense of some comfort:
Implement the interface Dumper on your types to take control of how your type is dumped.
type Dumper interface {
LitterDump(w io.Writer)
}
Just write your custom dump to the provided stream, using multiple lines divided by "\n" if you need. Litter
might indent your output according to context, and optionally decorate your first line with a pointer comment
where appropriate.
A couple of examples from the test suite:
type CustomMultiLineDumper struct {}
func (cmld *CustomMultiLineDumper) LitterDump(w io.Writer) {
w.Write([]byte("{\n multi\n line\n}"))
}
type CustomSingleLineDumper int
func (csld CustomSingleLineDumper) LitterDump(w io.Writer) {
w.Write([]byte("<custom>"))
}
sanity-io/litter thuộc nhóm Backend trên TopGit, cùng 6 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về sanity-io/litter ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/sanity-io/litter là nguồn chính thức.
sanity-io/litter có phải mã nguồn mở không?
Có — sanity-io/litter phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/sanity-io/litter.
sanity-io/litter là gì?
sanity-io/litter (sanity-io/litter) là dự án Go trên GitHub. Theo mô tả gốc: Litter is a pretty printer library for Go data structures to aid in debugging and testing.
sanity-io/litter so với các dự án Backend khác thế nào?
sanity-io/litter được TopGit xếp vào nhóm Backend, với 1.7k sao GitHub và viết bằng Go. Xem trang chủ đề Backend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Vì sao sanity-io/litter được xếp vào nhóm Backend?
TopGit xếp sanity-io/litter vào nhóm Backend dựa trên GitHub topics và mô tả của repo (gắn thẻ: "go", "golang", "library"). Việc phân loại dựa trên metadata thật của repo, không phải đoán theo cảm tính biên tập.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về litter?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về litter.