{"id":16788566,"url":"https://github.com/mna/starstruct","last_synced_at":"2026-03-14T09:04:33.451Z","repository":{"id":65752588,"uuid":"594284901","full_name":"mna/starstruct","owner":"mna","description":"Starlark to Go struct converter.","archived":false,"fork":false,"pushed_at":"2023-02-05T20:24:05.000Z","size":214,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-19T20:49:43.855Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mna.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["mna"],"custom":["https://www.buymeacoffee.com/mna"]}},"created_at":"2023-01-28T03:49:18.000Z","updated_at":"2024-10-20T18:53:07.000Z","dependencies_parsed_at":"2023-02-19T01:46:13.519Z","dependency_job_id":null,"html_url":"https://github.com/mna/starstruct","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/mna/starstruct","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mna%2Fstarstruct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mna%2Fstarstruct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mna%2Fstarstruct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mna%2Fstarstruct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mna","download_url":"https://codeload.github.com/mna/starstruct/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mna%2Fstarstruct/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272315605,"owners_count":24912609,"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","status":"online","status_checked_at":"2025-08-27T02:00:09.397Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-10-13T08:18:18.618Z","updated_at":"2026-03-14T09:04:33.420Z","avatar_url":"https://github.com/mna.png","language":"Go","funding_links":["https://github.com/sponsors/mna","https://www.buymeacoffee.com/mna"],"categories":["Libraries and extensions"],"sub_categories":[],"readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/mna/starstruct.svg)](https://pkg.go.dev/github.com/mna/starstruct)\n[![Build Status](https://github.com/mna/starstruct/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/mna/starstruct/actions)\n\n# Starlark to Go struct converter\n\nThe `starstruct` package implements conversion of Go structs to [Starlark `StringDict`](https://pkg.go.dev/go.starlark.net/starlark#StringDict) and from Starlark `StringDict` to a Go struct.\n\nIt uses the `starlark` struct tag key to indicate the name of the corresponding Starlark `StringDict` key for a field and optional conversion options, as is common in Go marshalers (such as [JSON](https://pkg.go.dev/encoding/json) and [XML](https://pkg.go.dev/encoding/xml)).\n\nSince Starlark is a useful language for configuration, and configuration can often be represented by a well-defined Go struct, the idea for this package is to make it easy to provide the default configuration (as a Go struct) to a Starlark program, and read back the final configuration after the Starlark program's execution, so that the Go code can use the Go configuration struct from there on.\n\nThe [code documentation](https://pkg.go.dev/github.com/mna/starstruct) is the canonical source for documentation.\n\n## Installation\n\nNote that `starstruct` requires Go 1.20+.\n\n```\n$ go get github.com/mna/starstruct\n```\n\n## Example\n\nFrom `example_test.go`:\n\n```golang\nfunc Example() {\n\tconst script = `\ndef set_server(srv):\n\tsrv[\"ports\"].append(2020)\n\ndef set_admin(adm):\n\tadm[\"name\"] = \"root\"\n\tadm[\"is_admin\"] = True\n\troles = adm[\"roles\"]\n\tadm[\"roles\"] = roles.union([\"editor\", \"admin\"])\n\nset_server(server)\nset_admin(user)\n`\n\n\ttype Server struct {\n\t\tAddr  string `starlark:\"addr\"`\n\t\tPorts []int  `starlark:\"ports\"`\n\t}\n\ttype User struct {\n\t\tName    string   `starlark:\"name\"`\n\t\tIsAdmin bool     `starlark:\"is_admin\"`\n\t\tIgnored int      `starlark:\"-\"`\n\t\tRoles   []string `starlark:\"roles,asset\"`\n\t}\n\ttype S struct {\n\t\tServer Server `starlark:\"server\"`\n\t\tUser   User   `starlark:\"user\"`\n\t}\n\n\t// initialize with default values for the starlark script\n\ts := S{\n\t\tServer: Server{Addr: \"localhost\", Ports: []int{80, 443}},\n\t\tUser:   User{Name: \"Martin\", Roles: []string{\"viewer\"}, Ignored: 42},\n\t}\n\tinitialVars := make(starlark.StringDict)\n\tif err := starstruct.ToStarlark(s, initialVars); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// execute the starlark script (it doesn't create any new variables, but if\n\t// it did, we would capture them in outputVars and merge all global vars\n\t// together before calling FromStarlark).\n\tvar th starlark.Thread\n\toutputVars, err := starlark.ExecFile(\u0026th, \"example\", script, initialVars)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tallVars := mergeStringDicts(nil, initialVars, outputVars)\n\n\tif err := starstruct.FromStarlark(allVars, \u0026s); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfmt.Printf(\"%v\", s)\n\n\t// Output:\n\t// {{localhost [80 443 2020]} {root true 42 [viewer editor admin]}}\n}\n```\n\n## License\n\nThe [BSD 3-Clause license](http://opensource.org/licenses/BSD-3-Clause).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmna%2Fstarstruct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmna%2Fstarstruct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmna%2Fstarstruct/lists"}