{"id":22997957,"url":"https://github.com/jritsema/gotoolbox","last_synced_at":"2025-08-13T23:32:53.977Z","repository":{"id":40570670,"uuid":"303803704","full_name":"jritsema/gotoolbox","owner":"jritsema","description":"A kitchen sink of useful Go tools","archived":false,"fork":false,"pushed_at":"2024-12-12T03:08:09.000Z","size":69,"stargazers_count":19,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-12T04:19:20.841Z","etag":null,"topics":["go","stdlib","toolbox","utils"],"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/jritsema.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-10-13T19:07:23.000Z","updated_at":"2024-12-12T03:08:13.000Z","dependencies_parsed_at":"2022-07-27T08:18:29.121Z","dependency_job_id":"430594e5-28f8-457b-a52f-6265d3b6d6dc","html_url":"https://github.com/jritsema/gotoolbox","commit_stats":{"total_commits":14,"total_committers":2,"mean_commits":7.0,"dds":0.4285714285714286,"last_synced_commit":"d1d21c1fcecbd3d0f115fcc52f43e6a71ffbf633"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jritsema%2Fgotoolbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jritsema%2Fgotoolbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jritsema%2Fgotoolbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jritsema%2Fgotoolbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jritsema","download_url":"https://codeload.github.com/jritsema/gotoolbox/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229787012,"owners_count":18124014,"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":["go","stdlib","toolbox","utils"],"created_at":"2024-12-15T06:10:01.503Z","updated_at":"2024-12-15T06:10:02.072Z","avatar_url":"https://github.com/jritsema.png","language":"Go","readme":"# gotoolbox\n\nA kitchen sink of Go tools that I've found useful. Uses only the standard library, no external dependencies.\n\n### contents\n\n- [super lightweight http server library](web)\n- [exponential backoff retry](retry.go)\n- [working with JSON](json.go)\n- [working with the file system](fs.go)\n- [working with slices](slice.go)\n- [working with CLIs](cli.go)\n\n### example usage\n\n```\ngo get github.com/jritsema/gotoolbox\n```\n\n### utilities\n\n```go\npackage main\n\nimport \"github.com/jritsema/gotoolbox\"\n\nfunc main() {\n\n\ts := []string{\"a\", \"b\", \"c\"}\n\tif gotoolbox.SliceContainsLike(\u0026s, \"b\") {\n\t\tfmt.Println(\"b exists\")\n\t}\n\n\terr := gotoolbox.Retry(3, 1, func() error {\n\t\treturn callBrittleAPI()\n\t})\n\tif err != nil {\n\t\tfmt.Println(\"callBrittleAPI failed after 3 retries: %w\", err)\n\t}\n\n\tf := \"config.json\"\n\tif !gotoolbox.IsDirectory(f) \u0026\u0026 gotoolbox.FileExists(f) {\n\t\tconfig, err := gotoolbox.ReadJSONFile(f)\n\t\tif err != nil {\n\t\t\tfmt.Println(\"error reading json file: %w\", err)\n\t\t}\n\t}\n\n\tvalue := gotoolbox.GetEnvWithDefault(\"MY_ENVVAR\", \"true\")\n\n\tcommand := exec.Command(\"docker\", \"build\", \"-t\", \"foo\", \".\")\n\terr = gotoolbox.ExecCmd(command, true)\n\tif err != nil {\n\t\tfmt.Println(\"error executing command: %w\", err)\n\t}\n\n\tvar data interface{}\n\terr = gotoolbox.HttpGetJSON(\"https://api.example.com/data.json\", \u0026data)\n\n\terr = gotoolbox.HttpPutJSON(\"https://api.example.com/data.json\", data)\n\n\tvar res Response\n\terr = gotoolbox.HttpPostJSON(\"https://api.example.com/data.json\", data, \u0026res, http.StatusCreated)\n}\n```\n\n#### web package\n\n```go\npackage main\n\nimport (\n\t\"embed\"\n\t\"html/template\"\n\t\"net/http\"\n\t\"github.com/jritsema/gotoolbox/web\"\n)\n\nvar (\n\t//go:embed all:templates/*\n\ttemplateFS embed.FS\n\thtml *template.Template\n)\n\ntype Data struct {\n\tHello string `json:\"hello\"`\n}\n\nfunc index(r *http.Request) *web.Response {\n\treturn web.HTML(http.StatusOK, html, \"index.html\", Data{Hello: \"world\"}, nil)\n}\n\nfunc api(r *http.Request) *web.Response {\n\treturn web.DataJSON(http.StatusOK, Data{Hello: \"world\"}, nil)\n}\n\nfunc main() {\n\thtml, _ = web.TemplateParseFSRecursive(templateFS, \".html\", true, nil)\n\tmux := http.NewServeMux()\n\tmux.Handle(\"/api\", web.Action(api))\n\tmux.Handle(\"/\", web.Action(index))\n\thttp.ListenAndServe(\":8080\", mux)\n}\n```\n\n### development\n\n```\n\nChoose a make command to run\n\nvet vet code\ntest run unit tests\nbuild build a binary\nautobuild auto build when source files change\nstart build and run local project\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjritsema%2Fgotoolbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjritsema%2Fgotoolbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjritsema%2Fgotoolbox/lists"}