{"id":18775998,"url":"https://github.com/way29/icecream-go","last_synced_at":"2025-04-13T09:31:41.528Z","repository":{"id":135492043,"uuid":"313613065","full_name":"WAY29/icecream-go","owner":"WAY29","description":"A Go port of Python's IceCream","archived":false,"fork":false,"pushed_at":"2024-03-22T06:13:18.000Z","size":16,"stargazers_count":82,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-18T23:16:07.077Z","etag":null,"topics":[],"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/WAY29.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"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-11-17T12:30:49.000Z","updated_at":"2024-04-18T06:33:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"482c2feb-6fda-415c-bdd7-96f56819c725","html_url":"https://github.com/WAY29/icecream-go","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WAY29%2Ficecream-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WAY29%2Ficecream-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WAY29%2Ficecream-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WAY29%2Ficecream-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WAY29","download_url":"https://codeload.github.com/WAY29/icecream-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223580158,"owners_count":17168580,"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":[],"created_at":"2024-11-07T19:44:28.875Z","updated_at":"2024-11-07T19:44:30.046Z","avatar_url":"https://github.com/WAY29.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IceCream-Go\n\nA Go port of Python's [IceCream](https://github.com/gruns/icecream).\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t. \"github.com/WAY29/icecream-go/icecream\"\n)\n\nfunc foo(a int) int {\n\treturn a + 333\n}\n\n\nfunc bar() {\n\tIc()\n}\n\nfunc main() {\n\tIc(foo(123))\n\t// Outputs:\n\t// ic| foo(123): 456\n\n\tIc(1 + 5)\n\t// Outputs:\n\t// ic| 1 + 5: 6\n\n\tIc(foo(123), 1 + 5)\n\t// Outputs:\n\t// ic| foo(123): 456, 1 + 5: 6\n\tbar()\n}\n// Outputs:\n// ic| main.go:12 in main.bar()\n```\n\n## Depends\n- [reflectsource](https://github.com/shurcooL/go/tree/master/reflectsource)\n\n\n## Installation\n\n```\ngo get -u \"github.com/WAY29/icecream-go/icecream\"\n```\n\n## Import\n\n```go\nimport ic \"github.com/WAY29/icecream-go/icecream\"\n// or just import . \"github.com/WAY29/icecream-go/icecream\"\n```\n\n## Configuration\n\nIf you want to change the prefix of the output, you can call `icecream.ConfigurePrefix(\"Hello| \")` (by default the prefix is `ic| `).\n\nIf you want to change how the result is outputted, you can call `icecream.ConfigureOutputFunction(f)`. func may be type of `func(s interface{})`.\nFor example, if you want to log your messages to a file:\n```go\nfunc logfile(s string) {\n\tfilePath := \"log.log\"\n\tfile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\tdefer file.Close()\n\twrite := bufio.NewWriter(file)\n\twrite.WriteString(s)\n\twrite.Flush()\n}\nfunc main() {\n\tic.ConfigureOutputFunction(logfile)\n\tic.Ic(1, 2, 3)\n\n\t// output to stringBuilder\n\tbuilder := strings.Builder{}\n\tic.ConfigureOutputFunction(\u0026builder)\n\tic.Ic(\"hello\")\n}\n```\n\nIf you want to change how the value is outputted, you can call `icecream.ConfigureArgToStringFunction(f)`, func may be type of `func(v interface{}) interface{}`.\nFor example, if you want to print more detail about a string:\n```go\nfunc toString(v interface{}) interface{} {\n    rv := reflect.ValueOf(v)\n    if rv.Kind() == reflect.String {\n        return fmt.Sprintf(\"[!string %#v with length %d!]\", v, len(v.(string)))\n    }\n    return fmt.Sprintf(\"%#v\", v)\n}\nfunc main() {\n    s := \"string\"\n    ic.ConfigureArgToStringFunction(toString)\n    ic.Ic(s)\n    ic.Ic(\"test\")\n}\n```\n\nIf you want to change the value name is outputted, you can call `icecream.ConfigureArgNameFormatterFunc`.\nFor example, if you want to print value name with ansi color:\n```go\nfunc main() {\n    s := \"string\"\n    ic.ConfigureArgNameFormatterFunc(func(name string) string {\n        return \"\\u001B[36m\" + name + \"\\u001B[0m\"\n    })\n    ic.Ic(s)\n    ic.Ic(\"test\")\n}\n```\n\nIf you want to add call's filename, line number, and parent function to ic's output, you can call `icecream.ConfigureIncludeContext(true)`.\n```go\nfunc main() {\n    ic.ConfigureIncludeContext(true)\n    ic.Ic(1, \"asd\")\n}\n```\n\nIf you want to reset configuration,  you can call `icecream.ResetPrefix()`,`icecream.ResetOutputFunction()`, `icecream.ResetArgToStringFunction()`,`icecream.ResetIncludeContext()` .\n\n## Return Value\n`Ic()` returns its arguments, so `Ic()` can easily be inserted into pre-existing code.\n\n```go\nfunc half(i interface{}) int {\n    if ii, ok := i.(int); ok {\n        return ii / 2\n    }\n\n    return -1\n}\n\n\nfunc main() {\n    a := 6\n    b := half(ic.Ic(a)[0])\n    ic.Ic(b)\n}\n```\nPrints\n```\nic| a: 6\nic| b: 3\n```\n\n## Miscellaneous\n\n`Format(...interface{})` is like `ic()` but the output is returned as a string instead of written to stderr.\n\n```go\nfunc main() {\n    result := ic.Format(\"sup\")\n    fmt.Printf(\"%s\", result)\n}\n```\n\nAdditionally, `Ic()`'s output can be entirely disabled, and later re-enabled, with `Disable()` and `Enable()` respectively.\n```go\nfunc main() {\n    ic.Ic(1)\n    ic.Disable()\n    ic.Ic(2)\n    ic.Enable()\n    ic.Ic(3)\n}\n```\nPrints\n```\nic| 1\nic| 3\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fway29%2Ficecream-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fway29%2Ficecream-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fway29%2Ficecream-go/lists"}