{"id":13562459,"url":"https://github.com/aosasona/gots","last_synced_at":"2026-03-20T00:59:24.339Z","repository":{"id":152129384,"uuid":"623044690","full_name":"aosasona/gots","owner":"aosasona","description":"No matter how you pronounce it, this repository is all about converting Go types to TypeScript types.","archived":true,"fork":false,"pushed_at":"2024-01-12T21:18:42.000Z","size":72,"stargazers_count":19,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-10T16:52:05.326Z","etag":null,"topics":["go","typescript"],"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/aosasona.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":"2023-04-03T15:24:35.000Z","updated_at":"2025-01-01T04:24:43.000Z","dependencies_parsed_at":"2024-01-13T03:23:59.629Z","dependency_job_id":"91e93954-b1e1-4572-bffd-aee8a3e56b93","html_url":"https://github.com/aosasona/gots","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aosasona%2Fgots","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aosasona%2Fgots/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aosasona%2Fgots/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aosasona%2Fgots/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aosasona","download_url":"https://codeload.github.com/aosasona/gots/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247057082,"owners_count":20876509,"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","typescript"],"created_at":"2024-08-01T13:01:08.883Z","updated_at":"2026-03-20T00:59:19.274Z","avatar_url":"https://github.com/aosasona.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"\u003e [!WARNING]\n\u003e This package has been renamed and because of that, development has moved [here](https://github.com/aosasona/mirror). This repo has been archived to prevent breaking your current usage.\n\n![gots](./assets/gots.png)\n\n## So, what is gots?\n\ngots allows you to generate usable TypeScript types from your selected Go types (int, string, struct etc) in the code itself.\n\n## Why would I do this?\n\n\u003e Let me paint you a picture\n\nYou have embedded React.js or Astro in your Go application (or you have them together in a monorepo) but now you have to define Typescript types for your Go's API responses (or other things) that you already have types for in your Go code.\n\nFine, you may feel okay with doing that, what happens when you change one of those types in the Go code? Now you need to update the matching TS type so you don't shoot yourself in the foot.\n\nBut you're human, you could easily forget and that's not great now, is it? That's where this package comes in, it generates the types during run-time which means it will always be up-to-date especially if you use something like air for hot-reloading.\n\n\u003e plus, I just enjoy building stuff like this\n\nView generated example [here](./examples/example.ts)\n\n## You should know...\n\nThe generated types may not always match what you expect (especially in the cases of embedded structs) and might just be an `any` or `unknown`, to be more specific, it is advised to use the type property in the `gots` or `ts` struct tag to specify the type yourself\nGots is not designed or built to be or ever be 100% accurate, just enough to have you setup and ready to communicate with your Go service/app/API _safely_ in Typescript, knowing a large part of what to send and expect back.\n\n# Installation\n\nJust paste this in your terminal (I promise it's safe):\n\n```bash\ngo get -u github.com/aosasona/gots/v2\n```\n\n# Usage\n\nNot an exceptional documentation but this should help you get started\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/aosasona/gots\"\n\t\"github.com/aosasona/gots/config\"\n)\n\ntype Language string\n\ntype Tags map[string]string\n\ntype Person struct {\n\tFName     string         `gots:\"name:first_name\"`\n\tLName     string         `gots:\"name:last_name\"`\n\tAge       int            `gots:\"name:age\"`\n\tLanguages []Language     `gots:\"name:languages\"`\n\tGrades    map[string]int `gots:\"name:grades,optional:1\"`\n\tTags      Tags           `gots:\"name:tags\"`\n\tCreatedAt time.Time      `gots:\"name:created_at\"`\n\tUpdatedAt *time.Time     `gots:\"name:updated_at\"`\n\tDeletedAt *time.Time     `gots:\"name:deleted_at\"`\n}\n\nfunc main() {\n\tgt := gots.Init(config.Config{\n\t\tEnabled:           gots.Bool(true),\n\t\tOutputFile:        gots.String(\"./examples/example.ts\"),\n\t\tUseTypeForObjects: gots.Bool(true),\n\t\tExpandObjectTypes: gots.Bool(true),\n\t})\n\n\t// ===\u003e Individually\n\tgt.AddSource(*new(Language))\n\tgt.AddSource(Tags{})\n\tgt.AddSource(Person{})\n\n\tout, err := gt.Generate()\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\t// save to file\n\terr = gt.Commit(out)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\t// ===\u003e As a group\n\tgt.Register(*new(Language), Tags{}, Person{})\n\n\t// generate types and save to the file\n\terr := gt.Execute(true)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n}\n```\n\nIt is safer to enable gots in development only, you can do this however way you want in your application. For example:\n\n```go\n...\nts := gots.Init(gots.Config{\n\tEnabled: os.Getenv(\"ENV\") == \"development\",\n})\n...\n```\n\n## Tags\n\nYou can configure the generated types using struct tags; the `json` tag, the `gots` tag or the legacy `ts` struct tag. You can pass in the following override values via struct field tags:\n\n- name (string)\n- type (string)\n- optional (only `true` or `1` or it is ignored)\n- skip (only `true` or `1`, but can also simply be written like this: `gots:\"-\"`)\n\n#### Example\n\n```go\ntype Ex struct {\n\tID\tstring `json:\"user_id,omitempty\" gots:\"type:Uppercase\u003cstring\u003e\"`\n\tName string `gots:\"name:fname,optional:true\"`\n}\n```\n\nThis will translate into:\n\n```typescript\nexport interface Ex {\n\tuser_id?: Uppercase\u003cstring\u003e;\n\tfname?: string;\n}\n```\n\nThese give you more control over what types end up being generated. You don't need to specify these, they are optional, if they are not specified, the default values are inferred from the types themselves.\n\n## Contribution\n\nPRs and issues are welcome :)\n\n## Development\n\n- To run the example:\n\n```sh\njust example\n```\n\n- To run the tests:\n\n```sh\njust test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faosasona%2Fgots","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faosasona%2Fgots","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faosasona%2Fgots/lists"}