{"id":13764136,"url":"https://github.com/galeone/rts","last_synced_at":"2025-06-15T21:04:38.907Z","repository":{"id":46780093,"uuid":"55412496","full_name":"galeone/rts","owner":"galeone","description":"RTS: request to struct. Generates Go structs from JSON server responses.","archived":false,"fork":false,"pushed_at":"2022-10-29T13:33:15.000Z","size":144,"stargazers_count":250,"open_issues_count":0,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-12T01:36:12.731Z","etag":null,"topics":["cli","go","golang","json","json-server","rest","rts"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/galeone.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":["galeone"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2016-04-04T13:17:19.000Z","updated_at":"2025-03-05T09:45:39.000Z","dependencies_parsed_at":"2023-01-20T09:48:04.799Z","dependency_job_id":null,"html_url":"https://github.com/galeone/rts","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galeone%2Frts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galeone%2Frts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galeone%2Frts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galeone%2Frts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/galeone","download_url":"https://codeload.github.com/galeone/rts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245755672,"owners_count":20667027,"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":["cli","go","golang","json","json-server","rest","rts"],"created_at":"2024-08-03T15:01:15.425Z","updated_at":"2025-03-27T00:11:02.424Z","avatar_url":"https://github.com/galeone.png","language":"Go","readme":"# RTS: Request to Struct\n\n[![GoDoc](https://godoc.org/github.com/galeone/rts?status.svg)](https://godoc.org/github.com/galeone/rts)\n[![Build Status](https://travis-ci.org/galeone/rts.svg?branch=master)](https://travis-ci.org/galeone/rts)\n\nGenerate Go structs definitions from JSON server responses.\n\nRTS defines type names using the specified lines in the route file and skipping numbers.\ne.g: a request to a route like `/users/1/posts` generates `type UsersPosts`\n\nIt supports *parameters*: a line like `/users/:user/posts/:pid 1 200` generates `type UsersUserPostsPid` from the response to the request `GET /users/1/posts/200`.\n\nRTS supports headers personalization as well, thus it can be used to generate types from responses protected by some authorization method\n\n## Install\n\n### CLI Application\n\n`go get -u github.com/galeone/rts/cmd/rts`\n\n#### CLI Usage\n\n```\nrts [options]\n  -headers string\n    \tHeaders to add in every request\n  -help\n    \tprints this help\n  -insecure\n    \tDisables TLS Certificate check for HTTPS, use in case HTTPS Server Certificate is signed by an unknown authority\n  -out string\n    \tOutput file. Stdout is used if not specified\n  -pkg string\n    \tPackage name (default \"main\")\n  -routes string\n    \tRoutes to request. One per line (default \"routes.txt\")\n  -server string\n    \tsets the server address (default \"http://localhost:9090\")\n  -substruct\n    \tCreates types for sub-structs\n```\n\n#### Examples\n\nYou can invoke `rts` piping from stdin a single JSON (anonymous) and get it converted to a go structure\n\n```\necho '  {\n    \"Book Id\": 30558257,\n    \"Title\": \"Unsouled (Cradle, #1)\",\n    \"Author\": \"Will Wight\",\n    \"Author l-f\": \"Wight, Will\",\n    \"Additional Authors\": \"\",\n    \"BCID\": \"\"\n  }' | ./rts\n```\n\nobtaining\n\n```go\npackage main\n\ntype Foo1 struct {\n        Additional_Authors string `json:\"Additional Authors\"`\n        Author             string `json:\"Author\"`\n        Author_l_f         string `json:\"Author l-f\"`\n        Bcid               string `json:\"BCID\"`\n        Book_Id            int64  `json:\"Book Id\"`\n        Title              string `json:\"Title\"`\n}\n```\n\nOr you can define a more complex scenario, definining the `routes.txt` file with a line for each (parametric) request and use it as shown below.\n\n*routes.txt*:\n\n```txt\n/\n/repos/:user/:repo galeone igor\n```\n\nRun:\n\n```\nrts -server https://api.github.com -pkg example\n```\n\nReturns:\n\n```go\npackage example\n\ntype Foo1 struct {\n\tAuthorizationsURL                string `json:\"authorizations_url\"`\n\tCodeSearchURL                    string `json:\"code_search_url\"`\n\tCommitSearchURL                  string `json:\"commit_search_url\"`\n\tCurrentUserAuthorizationsHTMLURL string `json:\"current_user_authorizations_html_url\"`\n\tCurrentUserRepositoriesURL       string `json:\"current_user_repositories_url\"`\n\tCurrentUserURL                   string `json:\"current_user_url\"`\n\tEmailsURL                        string `json:\"emails_url\"`\n\tEmojisURL                        string `json:\"emojis_url\"`\n\tEventsURL                        string `json:\"events_url\"`\n\tFeedsURL                         string `json:\"feeds_url\"`\n\tFollowersURL                     string `json:\"followers_url\"`\n\tFollowingURL                     string `json:\"following_url\"`\n\tGistsURL                         string `json:\"gists_url\"`\n\tHubURL                           string `json:\"hub_url\"`\n\tIssueSearchURL                   string `json:\"issue_search_url\"`\n\tIssuesURL                        string `json:\"issues_url\"`\n\tKeysURL                          string `json:\"keys_url\"`\n\tLabelSearchURL                   string `json:\"label_search_url\"`\n\tNotificationsURL                 string `json:\"notifications_url\"`\n\tOrganizationRepositoriesURL      string `json:\"organization_repositories_url\"`\n\tOrganizationTeamsURL             string `json:\"organization_teams_url\"`\n\tOrganizationURL                  string `json:\"organization_url\"`\n\tPublicGistsURL                   string `json:\"public_gists_url\"`\n\tRateLimitURL                     string `json:\"rate_limit_url\"`\n\tRepositorySearchURL              string `json:\"repository_search_url\"`\n\tRepositoryURL                    string `json:\"repository_url\"`\n\tStarredGistsURL                  string `json:\"starred_gists_url\"`\n\tStarredURL                       string `json:\"starred_url\"`\n\tTopicSearchURL                   string `json:\"topic_search_url\"`\n\tUserOrganizationsURL             string `json:\"user_organizations_url\"`\n\tUserRepositoriesURL              string `json:\"user_repositories_url\"`\n\tUserSearchURL                    string `json:\"user_search_url\"`\n\tUserURL                          string `json:\"user_url\"`\n}\n\ntype ReposUserRepo struct {\n\tAllowForking             bool               `json:\"allow_forking\"`\n\tArchiveURL               string             `json:\"archive_url\"`\n\tArchived                 bool               `json:\"archived\"`\n\tAssigneesURL             string             `json:\"assignees_url\"`\n\tBlobsURL                 string             `json:\"blobs_url\"`\n\tBranchesURL              string             `json:\"branches_url\"`\n\tCloneURL                 string             `json:\"clone_url\"`\n\tCollaboratorsURL         string             `json:\"collaborators_url\"`\n\tCommentsURL              string             `json:\"comments_url\"`\n\tCommitsURL               string             `json:\"commits_url\"`\n\tCompareURL               string             `json:\"compare_url\"`\n\tContentsURL              string             `json:\"contents_url\"`\n\tContributorsURL          string             `json:\"contributors_url\"`\n\tCreatedAt                string             `json:\"created_at\"`\n\tDefaultBranch            string             `json:\"default_branch\"`\n\tDeploymentsURL           string             `json:\"deployments_url\"`\n\tDescription              string             `json:\"description\"`\n\tDisabled                 bool               `json:\"disabled\"`\n\tDownloadsURL             string             `json:\"downloads_url\"`\n\tEventsURL                string             `json:\"events_url\"`\n\tFork                     bool               `json:\"fork\"`\n\tForks                    int64              `json:\"forks\"`\n\tForksCount               int64              `json:\"forks_count\"`\n\tForksURL                 string             `json:\"forks_url\"`\n\tFullName                 string             `json:\"full_name\"`\n\tGitCommitsURL            string             `json:\"git_commits_url\"`\n\tGitRefsURL               string             `json:\"git_refs_url\"`\n\tGitTagsURL               string             `json:\"git_tags_url\"`\n\tGitURL                   string             `json:\"git_url\"`\n\tHasDownloads             bool               `json:\"has_downloads\"`\n\tHasIssues                bool               `json:\"has_issues\"`\n\tHasPages                 bool               `json:\"has_pages\"`\n\tHasProjects              bool               `json:\"has_projects\"`\n\tHasWiki                  bool               `json:\"has_wiki\"`\n\tHomepage                 string             `json:\"homepage\"`\n\tHooksURL                 string             `json:\"hooks_url\"`\n\tHTMLURL                  string             `json:\"html_url\"`\n\tID                       int64              `json:\"id\"`\n\tIsTemplate               bool               `json:\"is_template\"`\n\tIssueCommentURL          string             `json:\"issue_comment_url\"`\n\tIssueEventsURL           string             `json:\"issue_events_url\"`\n\tIssuesURL                string             `json:\"issues_url\"`\n\tKeysURL                  string             `json:\"keys_url\"`\n\tLabelsURL                string             `json:\"labels_url\"`\n\tLanguage                 string             `json:\"language\"`\n\tLanguagesURL             string             `json:\"languages_url\"`\n\tLicense                  ReposUserRepo_sub1 `json:\"license\"`\n\tMergesURL                string             `json:\"merges_url\"`\n\tMilestonesURL            string             `json:\"milestones_url\"`\n\tMirrorURL                interface{}        `json:\"mirror_url\"`\n\tName                     string             `json:\"name\"`\n\tNetworkCount             int64              `json:\"network_count\"`\n\tNodeID                   string             `json:\"node_id\"`\n\tNotificationsURL         string             `json:\"notifications_url\"`\n\tOpenIssues               int64              `json:\"open_issues\"`\n\tOpenIssuesCount          int64              `json:\"open_issues_count\"`\n\tOwner                    ReposUserRepo_sub2 `json:\"owner\"`\n\tPrivate                  bool               `json:\"private\"`\n\tPullsURL                 string             `json:\"pulls_url\"`\n\tPushedAt                 string             `json:\"pushed_at\"`\n\tReleasesURL              string             `json:\"releases_url\"`\n\tSize                     int64              `json:\"size\"`\n\tSSHURL                   string             `json:\"ssh_url\"`\n\tStargazersCount          int64              `json:\"stargazers_count\"`\n\tStargazersURL            string             `json:\"stargazers_url\"`\n\tStatusesURL              string             `json:\"statuses_url\"`\n\tSubscribersCount         int64              `json:\"subscribers_count\"`\n\tSubscribersURL           string             `json:\"subscribers_url\"`\n\tSubscriptionURL          string             `json:\"subscription_url\"`\n\tSvnURL                   string             `json:\"svn_url\"`\n\tTagsURL                  string             `json:\"tags_url\"`\n\tTeamsURL                 string             `json:\"teams_url\"`\n\tTempCloneToken           interface{}        `json:\"temp_clone_token\"`\n\tTopics                   []string           `json:\"topics\"`\n\tTreesURL                 string             `json:\"trees_url\"`\n\tUpdatedAt                string             `json:\"updated_at\"`\n\tURL                      string             `json:\"url\"`\n\tVisibility               string             `json:\"visibility\"`\n\tWatchers                 int64              `json:\"watchers\"`\n\tWatchersCount            int64              `json:\"watchers_count\"`\n\tWebCommitSignoffRequired bool               `json:\"web_commit_signoff_required\"`\n}\n\ntype ReposUserRepo_sub2 struct {\n\tAvatarURL         string `json:\"avatar_url\"`\n\tEventsURL         string `json:\"events_url\"`\n\tFollowersURL      string `json:\"followers_url\"`\n\tFollowingURL      string `json:\"following_url\"`\n\tGistsURL          string `json:\"gists_url\"`\n\tGravatarID        string `json:\"gravatar_id\"`\n\tHTMLURL           string `json:\"html_url\"`\n\tID                int64  `json:\"id\"`\n\tLogin             string `json:\"login\"`\n\tNodeID            string `json:\"node_id\"`\n\tOrganizationsURL  string `json:\"organizations_url\"`\n\tReceivedEventsURL string `json:\"received_events_url\"`\n\tReposURL          string `json:\"repos_url\"`\n\tSiteAdmin         bool   `json:\"site_admin\"`\n\tStarredURL        string `json:\"starred_url\"`\n\tSubscriptionsURL  string `json:\"subscriptions_url\"`\n\tType              string `json:\"type\"`\n\tURL               string `json:\"url\"`\n}\n\ntype ReposUserRepo_sub1 struct {\n\tKey    string `json:\"key\"`\n\tName   string `json:\"name\"`\n\tNodeID string `json:\"node_id\"`\n\tSpdxID string `json:\"spdx_id\"`\n\tURL    string `json:\"url\"`\n}\n```\n\n### Library\n\n```go\nimport \"github.com/galeone/rts\"\n\nbyteFile, err := rts.Do(pkg, server, lines, headerMap)\n```\n\n# License\n\nRTS: Request to Struct. Generates Go structs from a server response.\nCopyright (C) 2016-2022 Paolo Galeone \u003cnessuno@nerdz.eu\u003e\n\nThis Source Code Form is subject to the terms of the Mozilla Public\nLicense, v. 2.0. If a copy of the MPL was not distributed with this\nfile, You can obtain one at http://mozilla.org/MPL/2.0/.\nExhibit B is not attached; this software is compatible with the\nlicenses expressed under Section 1.12 of the MPL v2.\n","funding_links":["https://github.com/sponsors/galeone"],"categories":["Go Tools","Go","Go 工具","Libraries for creating HTTP middlewares","Go工具","Go 語言工具","Go 语言工具"],"sub_categories":["Routers","路由器","路由","代码分析","Middlewares"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaleone%2Frts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgaleone%2Frts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaleone%2Frts/lists"}