{"id":43138006,"url":"https://github.com/ibllex/go-fractal","last_synced_at":"2026-01-31T22:09:38.713Z","repository":{"id":57619362,"uuid":"389312624","full_name":"ibllex/go-fractal","owner":"ibllex","description":"Output complex, flexible, AJAX/RESTful data structures.","archived":false,"fork":false,"pushed_at":"2021-12-30T04:31:21.000Z","size":27,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-19T20:03:18.825Z","etag":null,"topics":["api","fractal","gin","golang","json","restful","transformer"],"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/ibllex.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}},"created_at":"2021-07-25T09:47:20.000Z","updated_at":"2024-10-21T16:09:12.000Z","dependencies_parsed_at":"2022-09-16T19:01:58.843Z","dependency_job_id":null,"html_url":"https://github.com/ibllex/go-fractal","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ibllex/go-fractal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibllex%2Fgo-fractal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibllex%2Fgo-fractal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibllex%2Fgo-fractal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibllex%2Fgo-fractal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ibllex","download_url":"https://codeload.github.com/ibllex/go-fractal/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibllex%2Fgo-fractal/sbom","scorecard":{"id":479188,"data":{"date":"2025-08-11","repo":{"name":"github.com/ibllex/go-fractal","commit":"6544a7b753957008cf2596e957de65abee0c655a"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.2,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/ibllex/go-fractal/test.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/ibllex/go-fractal/test.yml/main?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/8 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/test.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":7,"reason":"3 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GO-2021-0052 / GHSA-h395-qcrw-5vmq","Warn: Project is vulnerable to: GHSA-3vp4-m3rf-835h","Warn: Project is vulnerable to: GO-2023-1737 / GHSA-2c4m-59x9-fr2g"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T16:08:14.887Z","repository_id":57619362,"created_at":"2025-08-19T16:08:14.887Z","updated_at":"2025-08-19T16:08:14.887Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28957108,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T18:30:42.805Z","status":"ssl_error","status_checked_at":"2026-01-31T18:30:19.593Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["api","fractal","gin","golang","json","restful","transformer"],"created_at":"2026-01-31T22:09:38.058Z","updated_at":"2026-01-31T22:09:38.709Z","avatar_url":"https://github.com/ibllex.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go-Fractal\n\ngo-fractal is the go version of [league/fractal](https://github.com/thephpleague/fractal) which is is written in PHP, fractal provides a presentation and transformation layer for complex data output, the like found in RESTful APIs, and works really well with JSON. Think of this as a view layer for your JSON/YAML/etc.\n\n## Install\n\n```bash\ngo get -u github.com/ibllex/go-fractal\n```\n\n## Quick usage\n\n\u003e For the sake of simplicity, this example has been put together as though it was one file. In reality you would spread the manager initiation, data collection and JSON conversion into separate parts of your application.\n\n### Transform an item\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/ibllex/go-fractal\"\n)\n\ntype Book struct {\n\tID     int\n\tTitle  string\n\tYear   int\n\tAuthor string\n}\n\nfunc main() {\n\n\t// This is the data to be converted\n\tdata := \u0026Book{1, \"Hogfather\", 1998, \"Philip K Dick\"}\n\n\t// Create a top level instance\n\tmanager := fractal.NewManager(nil)\n\tmanager.SetSerializer(\u0026fractal.ArraySerializer{})\n\n\t// This \"Transformer\" can be a callback or a new instance of a fractal.Transformer object\n\ttransformer := fractal.T(func(t *fractal.BaseTransformer, data fractal.Any) fractal.M {\n\t\tresult := fractal.M{}\n\n\t\tif b, ok := data.(*Book); ok {\n\t\t\tresult[\"id\"] = b.ID\n\t\t\tresult[\"title\"] = \"'\" + b.Title + \"'\"\n\t\t\tresult[\"year\"] = b.Year\n\t\t\tresult[\"author\"] = b.Author\n\t\t}\n\n\t\treturn result\n\t})\n\n\t// Convert the single book into an item resource\n\tresource := fractal.NewItem(\n\t\tfractal.WithData(data),\n\t\tfractal.WithTransformer(transformer),\n\t)\n\n\t// Turn all of that into a JSON string\n\tjson, _ := manager.CreateData(resource, nil).ToJSON()\n\n\tfmt.Println(json)\n\t// Outputs: {\"data\":{\"author\":\"Philip K Dick\",\"id\":1,\"title\":\"'Hogfather'\",\"year\":1998}}\n}\n```\n\n### Transform a collection of data\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/ibllex/go-fractal\"\n)\n\ntype Book struct {\n\tID     int\n\tTitle  string\n\tYear   int\n\tAuthor string\n}\n\nfunc main() {\n\n\t// This is the data to be converted\n\tbooks := []fractal.Any{\n\t\t\u0026Book{1, \"Hogfather\", 1998, \"Philip K Dick\"},\n\t\t\u0026Book{2, \"Game Of Kill Everyone\", 2014, \"George R. R. Satan\"},\n\t}\n\n\t// Create a top level instance\n\tmanager := fractal.NewManager(nil)\n\tmanager.SetSerializer(\u0026fractal.ArraySerializer{})\n\n\t// This \"Transformer\" can be a callback or a new instance of a fractal.Transformer object\n\ttransformer := fractal.T(func(t *fractal.BaseTransformer, data fractal.Any) fractal.M {\n\t\tresult := fractal.M{}\n\n\t\tif b, ok := data.(*Book); ok {\n\t\t\tresult[\"id\"] = b.ID\n\t\t\tresult[\"title\"] = \"'\" + b.Title + \"'\"\n\t\t\tresult[\"year\"] = b.Year\n\t\t\tresult[\"author\"] = b.Author\n\t\t}\n\n\t\treturn result\n\t})\n\n\t// Convert the books into a collection resource\n\tresource := fractal.NewCollection(\n\t\tfractal.WithData(books),\n\t\tfractal.WithTransformer(transformer),\n\t)\n\n\t// Turn all of that into a JSON string\n\tjson, _ := manager.CreateData(resource, nil).ToJSON()\n\n\tfmt.Println(json)\n\t// Outputs: {\"data\":[{\"author\":\"Philip K Dick\",\"id\":1,\"title\":\"'Hogfather'\",\"year\":1998},{\"author\":\"George R. R. Satan\",\"id\":2,\"title\":\"'Game Of Kill Everyone'\",\"year\":2014}]}\n}\n```\n\n### Transform with pagination\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/ibllex/go-fractal\"\n\t\"github.com/ibllex/go-fractal/pagination\"\n)\n\ntype Book struct {\n\tID     int\n\tTitle  string\n\tYear   int\n\tAuthor string\n}\n\nfunc main() {\n\n\t// This is the data to be converted\n\tbooks := []fractal.Any{\n\t\t\u0026Book{1, \"Hogfather\", 1998, \"Philip K Dick\"},\n\t\t\u0026Book{2, \"Game Of Kill Everyone\", 2014, \"George R. R. Satan\"},\n\t}\n\n\t// Create an paginator\n\tpaginator := pagination.NewLengthAwarePaginator(\n\t\tbooks, 10, 2,\n\t\tpagination.WithPath(\"https://www.example.com/books/?user=example\"),\n\t\tpagination.WithCurrentPage(2),\n\t)\n\n\t// Create a top level instance\n\tmanager := fractal.NewManager(nil)\n\tmanager.SetSerializer(\u0026fractal.ArraySerializer{})\n\n\t// This \"Transformer\" can be a callback or a new instance of a fractal.Transformer object\n\ttransformer := fractal.T(func(t *fractal.BaseTransformer, data fractal.Any) fractal.M {\n\t\tresult := fractal.M{}\n\n\t\tif b, ok := data.(*Book); ok {\n\t\t\tresult[\"id\"] = b.ID\n\t\t\tresult[\"title\"] = \"'\" + b.Title + \"'\"\n\t\t\tresult[\"year\"] = b.Year\n\t\t\tresult[\"author\"] = b.Author\n\t\t}\n\n\t\treturn result\n\t})\n\n\t// Convert the books into a collection resource with a paginator\n\tresource := fractal.NewCollection(\n\t\tfractal.WithData(books),\n\t\tfractal.WithTransformer(transformer),\n\t).SetPaginator(paginator)\n\n\t// Turn all of that into a JSON string\n\tjson, _ := manager.CreateData(resource, nil).ToJSON()\n\n\tfmt.Println(json)\n\t// Outputs: {\"data\":[{\"author\":\"Philip K Dick\",\"id\":1,\"title\":\"'Hogfather'\",\"year\":1998},{\"author\":\"George R. R. Satan\",\"id\":2,\"title\":\"'Game Of Kill Everyone'\",\"year\":2014}],\"meta\":{\"pagination\":{\"count\":2,\"current_page\":2,\"links\":{\"next\":\"https://www.example.com/books/?user=example\u0026page=3\",\"previous\":\"https://www.example.com/books/?user=example\u0026page=1\"},\"per_page\":2,\"total\":10,\"total_pages\":5}}}\n}\n```\n\n### Use with gin\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/gin-gonic/gin\"\n\t\"github.com/ibllex/go-fractal\"\n\tfgin \"github.com/ibllex/go-fractal/gin\"\n\t\"github.com/ibllex/go-fractal/pagination\"\n)\n\ntype Book struct {\n\tID     int\n\tTitle  string\n\tYear   int\n\tAuthor string\n}\n\ntype BookTransformer struct {\n\t*fractal.BaseTransformer\n}\n\nfunc (t *BookTransformer) Transform(data fractal.Any) fractal.M {\n\tresult := fractal.M{}\n\n\tif b := t.toBook(data); b != nil {\n\t\tresult[\"id\"] = b.ID\n\t\tresult[\"title\"] = \"'\" + b.Title + \"'\"\n\t\tresult[\"year\"] = b.Year\n\t\tresult[\"author\"] = b.Author\n\t}\n\n\treturn result\n}\n\nfunc (t *BookTransformer) toBook(data fractal.Any) *Book {\n\n\tswitch b := data.(type) {\n\tcase *Book:\n\t\treturn b\n\tcase Book:\n\t\treturn \u0026b\n\t}\n\n\treturn nil\n}\n\nfunc NewBookTransformer() *BookTransformer {\n\treturn \u0026BookTransformer{\u0026fractal.BaseTransformer{}}\n}\n\nfunc GetBook(c *fgin.Context) {\n\t// This is the data to be converted\n\tdata := \u0026Book{1, \"Hogfather\", 1998, \"Philip K Dick\"}\n\n\t// Turn all of that into a JSON output\n\tc.Item(data, NewBookTransformer())\n\t// Outputs: {\"data\":{\"author\":\"Philip K Dick\",\"id\":1,\"title\":\"'Hogfather'\",\"year\":1998}}\n}\n\nfunc GetBooks(c *fgin.Context) {\n\t// This is the data to be converted\n\tbooks := []fractal.Any{\n\t\t\u0026Book{1, \"Hogfather\", 1998, \"Philip K Dick\"},\n\t\t\u0026Book{2, \"Game Of Kill Everyone\", 2014, \"George R. R. Satan\"},\n\t}\n\n\t// Create an paginator\n\tpaginator := pagination.NewLengthAwarePaginator(\n\t\tbooks, 10, 2,\n\t\tpagination.WithPath(\"https://www.example.com/books/?user=example\"),\n\t\tpagination.WithCurrentPage(2),\n\t)\n\n\t// Turn all of that into a JSON output with pagination\n\tc.Paginator(paginator, NewBookTransformer())\n\t// Outputs: {\"data\":[{\"author\":\"Philip K Dick\",\"id\":1,\"title\":\"'Hogfather'\",\"year\":1998},{\"author\":\"George R. R. Satan\",\"id\":2,\"title\":\"'Game Of Kill Everyone'\",\"year\":2014}],\"meta\":{\"pagination\":{\"count\":2,\"current_page\":2,\"links\":{\"next\":\"https://www.example.com/books/?user=example\\u0026page=3\",\"previous\":\"https://www.example.com/books/?user=example\\u0026page=1\"},\"per_page\":2,\"total\":10,\"total_pages\":5}}}\n\n\t// You can also use c.Collection() to transform a collection without pagination\n\t// c.Collection(books, NewBookTransformer())\n\t// Outputs: {\"data\":[{\"author\":\"Philip K Dick\",\"id\":1,\"title\":\"'Hogfather'\",\"year\":1998},{\"author\":\"George R. R. Satan\",\"id\":2,\"title\":\"'Game Of Kill Everyone'\",\"year\":2014}]}\n}\n\nfunc NotFound(c *fgin.Context) {\n\t// A convenient way to return a 404 status,\n\t// We also provide many other methods to return error messages easily,\n\t// For more infomation: https://github.com/ibllex/go-fractal/blob/main/gin/context.go\n\tc.ErrorNotFound()\n\t// Outputs: {\"message\":\"Not Found\",\"status_code\":404}\n}\n\nfunc main() {\n\tr := gin.Default()\n\n\tr.GET(\"/books\", fgin.H(GetBooks))\n\tr.GET(\"/book\", fgin.H(GetBook))\n\tr.GET(\"/404\", fgin.H(NotFound))\n\n\tsrv := http.Server{\n\t\tAddr:    fmt.Sprintf(\":%d\", 8080),\n\t\tHandler: r,\n\t}\n\n\tlog.Printf(\"HTTP Service Started at %s\", srv.Addr)\n\tsrv.ListenAndServe()\n}\n```\n\n## License\n\nThis library is under the [MIT](https://github.com/ibllex/go-fractal/blob/main/LICENSE) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibllex%2Fgo-fractal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibllex%2Fgo-fractal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibllex%2Fgo-fractal/lists"}