RTS: request to struct. Generates Go structs from JSON server responses.
Generate Go structs definitions from JSON server responses.
RTS defines type names using the specified lines in the route file and skipping numbers. e.g: a request to a route like
/users/1/postsgenerates
type UsersPosts
It supports parameters: a line like
/users/:user/posts/:pid 1 200generates
type UsersUserPostsPidfrom the response to the request
GET /users/1/posts/200.
RTS supports headers personalization as well, thus it can be used to generate types from responses protected by some authorization method
Updated: 6/17/2016 by Krish Verma https://github.com/kverma
In case the JSON server is HTTPS with unknown certificate signing authority, pass the -insecure flag to disable TLS certificate check
go get -u github.com/galeone/rts/cmd/rts
import "github.com/galeone/rts"byteFile, err := rts.Do(pkg, server, lines, headerMap)
rts [options] -headers string Headers to add in every request -help prints this help -insecure Disables TLS Certificate check for HTTPS, use in case HTTPS Server Certificate is signed by an unknown authority -out string Output file. Stdout is used if not specified -pkg string Package name (default "main") -routes string Routes to request. One per line (default "routes.txt") -server string sets the server address (default "http://localhost:9090") -substruct Creates types for sub-structs
routes.txt:
/ /repos/:user/:repo galeone igor
Run:
rts -server https://api.github.com -pkg example
Returns:
package exampletype Foo1 struct { AuthorizationsURL string
json:"authorizations_url"
CodeSearchURL stringjson:"code_search_url"
CurrentUserAuthorizationsHTMLURL stringjson:"current_user_authorizations_html_url"
CurrentUserRepositoriesURL stringjson:"current_user_repositories_url"
CurrentUserURL stringjson:"current_user_url"
EmailsURL stringjson:"emails_url"
EmojisURL stringjson:"emojis_url"
EventsURL stringjson:"events_url"
FeedsURL stringjson:"feeds_url"
FollowersURL stringjson:"followers_url"
FollowingURL stringjson:"following_url"
GistsURL stringjson:"gists_url"
HubURL stringjson:"hub_url"
IssueSearchURL stringjson:"issue_search_url"
IssuesURL stringjson:"issues_url"
KeysURL stringjson:"keys_url"
NotificationsURL stringjson:"notifications_url"
OrganizationRepositoriesURL stringjson:"organization_repositories_url"
OrganizationURL stringjson:"organization_url"
PublicGistsURL stringjson:"public_gists_url"
RateLimitURL stringjson:"rate_limit_url"
RepositorySearchURL stringjson:"repository_search_url"
RepositoryURL stringjson:"repository_url"
StarredGistsURL stringjson:"starred_gists_url"
StarredURL stringjson:"starred_url"
TeamURL stringjson:"team_url"
UserOrganizationsURL stringjson:"user_organizations_url"
UserRepositoriesURL stringjson:"user_repositories_url"
UserSearchURL stringjson:"user_search_url"
UserURL stringjson:"user_url"
}type ReposUserRepo struct { ArchiveURL string
json:"archive_url"
AssigneesURL stringjson:"assignees_url"
BlobsURL stringjson:"blobs_url"
BranchesURL stringjson:"branches_url"
CloneURL stringjson:"clone_url"
CollaboratorsURL stringjson:"collaborators_url"
CommentsURL stringjson:"comments_url"
CommitsURL stringjson:"commits_url"
CompareURL stringjson:"compare_url"
ContentsURL stringjson:"contents_url"
ContributorsURL stringjson:"contributors_url"
CreatedAt stringjson:"created_at"
DefaultBranch stringjson:"default_branch"
DeploymentsURL stringjson:"deployments_url"
Description stringjson:"description"
DownloadsURL stringjson:"downloads_url"
EventsURL stringjson:"events_url"
Fork booljson:"fork"
Forks intjson:"forks"
ForksCount intjson:"forks_count"
ForksURL stringjson:"forks_url"
FullName stringjson:"full_name"
GitCommitsURL stringjson:"git_commits_url"
GitRefsURL stringjson:"git_refs_url"
GitTagsURL stringjson:"git_tags_url"
GitURL stringjson:"git_url"
HasDownloads booljson:"has_downloads"
HasIssues booljson:"has_issues"
HasPages booljson:"has_pages"
HasWiki booljson:"has_wiki"
Homepage stringjson:"homepage"
HooksURL stringjson:"hooks_url"
HTMLURL stringjson:"html_url"
ID intjson:"id"
IssueCommentURL stringjson:"issue_comment_url"
IssueEventsURL stringjson:"issue_events_url"
IssuesURL stringjson:"issues_url"
KeysURL stringjson:"keys_url"
LabelsURL stringjson:"labels_url"
Language stringjson:"language"
LanguagesURL stringjson:"languages_url"
MergesURL stringjson:"merges_url"
MilestonesURL stringjson:"milestones_url"
MirrorURL interface{}json:"mirror_url"
Name stringjson:"name"
NetworkCount intjson:"network_count"
NotificationsURL stringjson:"notifications_url"
OpenIssues intjson:"open_issues"
OpenIssuesCount intjson:"open_issues_count"
Owner struct { AvatarURL stringjson:"avatar_url"
EventsURL stringjson:"events_url"
FollowersURL stringjson:"followers_url"
FollowingURL stringjson:"following_url"
GistsURL stringjson:"gists_url"
GravatarID stringjson:"gravatar_id"
HTMLURL stringjson:"html_url"
ID intjson:"id"
Login stringjson:"login"
OrganizationsURL stringjson:"organizations_url"
ReceivedEventsURL stringjson:"received_events_url"
ReposURL stringjson:"repos_url"
SiteAdmin booljson:"site_admin"
StarredURL stringjson:"starred_url"
SubscriptionsURL stringjson:"subscriptions_url"
Type stringjson:"type"
URL stringjson:"url"
}json:"owner"
Private booljson:"private"
PullsURL stringjson:"pulls_url"
PushedAt stringjson:"pushed_at"
ReleasesURL stringjson:"releases_url"
Size intjson:"size"
SSHURL stringjson:"ssh_url"
StargazersCount intjson:"stargazers_count"
StargazersURL stringjson:"stargazers_url"
StatusesURL stringjson:"statuses_url"
SubscribersCount intjson:"subscribers_count"
SubscribersURL stringjson:"subscribers_url"
SubscriptionURL stringjson:"subscription_url"
SvnURL stringjson:"svn_url"
TagsURL stringjson:"tags_url"
TeamsURL stringjson:"teams_url"
TreesURL stringjson:"trees_url"
UpdatedAt stringjson:"updated_at"
URL stringjson:"url"
Watchers intjson:"watchers"
WatchersCount intjson:"watchers_count"
}
RTS: Request to Struct. Generates Go structs from a server response. Copyright (C) 2016 Paolo Galeone [email protected]
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. Exhibit B is not attached; this software is compatible with the licenses expressed under Section 1.12 of the MPL v2.