{"id":21626958,"url":"https://github.com/komuw/kama","last_synced_at":"2025-03-18T20:25:27.933Z","repository":{"id":45147803,"uuid":"282230972","full_name":"komuw/kama","owner":"komuw","description":"kama prints exported information of types, variables, packages, modules, imports etc. It also pretty prints data structures. It can be used to aid debugging and testing.","archived":false,"fork":false,"pushed_at":"2024-03-12T21:21:36.000Z","size":11338,"stargazers_count":2,"open_issues_count":7,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-24T22:44:07.215Z","etag":null,"topics":["ast","dir","go","golang","pretty","pretty-print","print","repr","testing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/komuw.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-24T13:45:42.000Z","updated_at":"2023-02-21T16:13:47.000Z","dependencies_parsed_at":"2024-01-31T16:12:47.107Z","dependency_job_id":"8be0f21a-cb8e-44b6-8e86-d09a0e3dcc24","html_url":"https://github.com/komuw/kama","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komuw%2Fkama","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komuw%2Fkama/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komuw%2Fkama/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komuw%2Fkama/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/komuw","download_url":"https://codeload.github.com/komuw/kama/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244299449,"owners_count":20430606,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","dir","go","golang","pretty","pretty-print","print","repr","testing"],"created_at":"2024-11-25T01:14:56.254Z","updated_at":"2025-03-18T20:25:27.901Z","avatar_url":"https://github.com/komuw.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## kama          \n\n[![Go Reference](https://pkg.go.dev/badge/github.com/komuw/kama.svg)](https://pkg.go.dev/github.com/komuw/kama)\n[![ci](https://github.com/komuw/kama/workflows/kama%20ci/badge.svg)](https://github.com/komuw/kama/actions)\n[![codecov](https://codecov.io/gh/komuw/kama/branch/main/graph/badge.svg)](https://codecov.io/gh/komuw/kama)\n\n\n`kama` prints exported information of types, variables, packages, modules, imports etc     \nIt also pretty prints data structures.    \nIt can be used to aid debugging and testing.        \nIf you have heard of [kr/pretty](https://github.com/kr/pretty), [sanity-io/litter](https://github.com/sanity-io/litter), [davecgh/go-spew](https://github.com/davecgh/go-spew) etc; then `kama` is like those except that it;   \n(a) prints the exported API of types, modules etc     \nand     \n(b) pretty prints data structures.         \n\nIt is heavily inspired by Python's [`dir`](https://docs.python.org/3/library/functions.html#dir) builtin function.       \n\nIt's name is derived from Kenyan hip hop artiste, `Kama`(One third of the hiphop group `Kalamashaka`).                               \n\n\n## Installation\n\n```shell\ngo get -u github.com/komuw/kama\n```\n\n## API:\n```go\nfunc Dirp(i interface{}, c ...Config)\n    Dirp prints exported information of types, variables, packages,\n    modules, imports. It also pretty prints data structures.\n\nfunc Diffp(old, new interface{}, c ...Config)\n    Diffp prints a formatted diff showing the minimum line-level additions and\n    removals that would turn old into new.\n\nfunc Stackp()\n    Stackp prints the colorized stack trace.\n    Stack trace from the runtime/stdlib is colored blue, third party libraries\n    is yellow whereas your code is red.\n```\n\n## Usage:    \n\n#### (a) print exported api of modules\n```go\nimport \"github.com/komuw/kama\"\n\nkama.Dirp(\"compress/flate\")\nkama.Dirp(\"github.com/pkg/errors\")\n```\nthat will print:\n```bash\n[\nNAME: compress/flate\nCONSTANTS: [\n    BestCompression untyped int \n    BestSpeed untyped int \n    DefaultCompression untyped int \n    HuffmanOnly untyped int \n    NoCompression untyped int \n    ]\nVARIABLES: []\nFUNCTIONS: [\n    NewReader(r io.Reader) io.ReadCloser \n    NewReaderDict(r io.Reader, dict []byte) io.ReadCloser \n    NewWriter(w io.Writer, level int) (*Writer, error) \n    NewWriterDict(w io.Writer, level int, dict []byte) (*Writer, error) \n    ]\nTYPES: [\n    CorruptInputError int64\n        (CorruptInputError) Error() string \n    InternalError string\n        (InternalError) Error() string \n    ReadError struct\n        (*ReadError) Error() string \n    Reader interface\n        (Reader) Read(p []byte) (n int, err error)\n        (Reader) ReadByte() (byte, error) \n    Resetter interface\n        (Resetter) Reset(r io.Reader, dict []byte) error \n    WriteError struct\n        (*WriteError) Error() string \n    Writer struct\n        (*Writer) Close() error\n        (*Writer) Flush() error\n        (*Writer) Reset(dst io.Writer)\n        (*Writer) Write(data []byte) (n int, err error)]\n]\n```\n```bash\n[\nNAME: github.com/pkg/errors\nCONSTANTS: []\nVARIABLES: []\nFUNCTIONS: [\n    As(err error, target interface{}) bool \n    Cause(err error) error \n    Errorf(format string, args ...interface{}) error \n    Is(err error, target error) bool \n    New(message string) error \n    Unwrap(err error) error \n    WithMessage(err error, message string) error \n    WithMessagef(err error, format string, args ...interface{}) error \n    WithStack(err error) error \n    Wrap(err error, message string) error \n    Wrapf(err error, format string, args ...interface{}) error \n    ]\nTYPES: [\n    Frame uintptr\n        (Frame) Format(s fmt.State, verb rune)\n        (Frame) MarshalText() ([]byte, error) \n    StackTrace []Frame\n        (StackTrace) Format(s fmt.State, verb rune)]\n]\n```\n\n#### (b) pretty data structures:\n```go\nreq, _ := http.NewRequest(\"GET\", \"https://example.com\", nil)\nreq.Header.Set(\"Content-Type\", \"application/octet-stream\")\nreq.AddCookie(\u0026http.Cookie{Name: \"hello\", Value: \"world\"})\n\nkama.Dirp(req)\n// kama.Dirp(req, kama.Config{MaxLength: 14}) // pass in an optional config value.\n```\nthat will print:\n```bash\n[\nNAME: net/http.Request\nKIND: struct\nSIGNATURE: [*http.Request http.Request]\nFIELDS: [\n\tMethod string \n\tURL *url.URL \n\tProto string \n\tProtoMajor int \n\tProtoMinor int \n\tHeader http.Header \n\tBody io.ReadCloser \n\tGetBody func() (io.ReadCloser, error) \n\tContentLength int64 \n\tTransferEncoding []string \n\tClose bool \n\tHost string \n\tForm url.Values \n\tPostForm url.Values \n\tMultipartForm *multipart.Form \n\tTrailer http.Header \n\tRemoteAddr string \n\tRequestURI string \n\tTLS *tls.ConnectionState \n\tCancel \u003c-chan struct {} \n\tResponse *http.Response \n\t]\nMETHODS: [\n\tAddCookie func(*http.Request, *http.Cookie) \n\tBasicAuth func(*http.Request) (string, string, bool) \n\tClone func(*http.Request, context.Context) *http.Request \n\tContext func(*http.Request) context.Context \n\tCookie func(*http.Request, string) (*http.Cookie, error) \n\tCookies func(*http.Request) []*http.Cookie \n\tFormFile func(*http.Request, string) (multipart.File, *multipart.FileHeader, error) \n\tFormValue func(*http.Request, string) string \n\tMultipartReader func(*http.Request) (*multipart.Reader, error) \n\tParseForm func(*http.Request) error \n\tParseMultipartForm func(*http.Request, int64) error \n\tPathValue func(*http.Request, string) string \n\tPostFormValue func(*http.Request, string) string \n\tProtoAtLeast func(*http.Request, int, int) bool \n\tReferer func(*http.Request) string \n\tSetBasicAuth func(*http.Request, string, string) \n\tSetPathValue func(*http.Request, string, string) \n\tUserAgent func(*http.Request) string \n\tWithContext func(*http.Request, context.Context) *http.Request \n\tWrite func(*http.Request, io.Writer) error \n\tWriteProxy func(*http.Request, io.Writer) error \n\t]\nSTACK_TRACE: [\nLEGEND:\n compiler: blue\n thirdParty: yellow\n yours: red\n\n    /home/komu/mystuff/kama/kama.go:129 github.com/komuw/kama.Dir\n    /home/komu/mystuff/kama/kama_test.go:244 github.com/komuw/kama.TestReadmeExamples.func1\n    /usr/local/go/src/testing/testing.go:1689 testing.tRunner\n    /usr/local/go/src/runtime/asm_amd64.s:1695 runtime.goexit\n]\nSNIPPET: \u0026Request{\n  Method: \"GET\",\n  URL: \u0026URL{\n    Scheme: \"https\",\n    Host: \"example.com\",\n  },\n  Proto: \"HTTP/1.1\",\n  ProtoMajor: int(1),\n  ProtoMinor: int(1),\n  Header: http.Header{\n   \"Content-Type\": []string{\n   \"application/octet-stream\",\n      }, \n   \"Cookie\": []string{\n   \"hello=world\",\n      }, \n    },\n  Body: io.ReadCloser nil,\n  GetBody: func() (io.ReadCloser, error),\n  ContentLength: int64(0),\n  TransferEncoding: []string{(nil)},\n  Close: false,\n  Host: \"example.com\",\n  Form: url.Values{(nil)},\n  PostForm: url.Values{(nil)},\n  MultipartForm: *multipart.Form(nil),\n  Trailer: http.Header{(nil)},\n  RemoteAddr: \"\",\n  RequestURI: \"\",\n  TLS: *tls.ConnectionState(nil),\n  Cancel: \u003c-chan struct {} (len=0, cap=0),\n  Response: *http.Response(nil),\n}\n]\n```\nSee [testdata](testdata) directory for more examples.    \n\n## Testing\n```shell\n# run tests:\nexport KAMA_WRITE_DATA_FOR_TESTS=YES\nunset KAMA_WRITE_DATA_FOR_TESTS\ngo test -race ./... -trimpath -count=1\n```\n\n## Inspiration\n1. Python's [`dir`](https://docs.python.org/3/library/functions.html#dir) builtin function.    \n2. [`godex`](https://pkg.go.dev/golang.org/x/tools/cmd/godex).   \n3. [`sanity-io/litter`](https://github.com/sanity-io/litter).\n\n## Prior art\n1. https://github.com/kr/pretty\n2. https://github.com/sanity-io/litter\n3. https://github.com/davecgh/go-spew\n4. https://github.com/hexops/valast\n5. https://github.com/alecthomas/repr\n6. https://github.com/k0kubun/pp\n7. https://github.com/jba/printsrc\n8. https://github.com/kylelemons/godebug\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkomuw%2Fkama","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkomuw%2Fkama","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkomuw%2Fkama/lists"}