-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go-swagger example from source #3
base: main
Are you sure you want to change the base?
Conversation
"github.com/shapeshift/unchained-cosmos/service" | ||
) | ||
|
||
// swagger:route GET /account/{pubkey} account-tag accountEndpointId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These can live anywhere that is a child of the main.go.
It could be placed next to each endpoint but the example I was looking at kept it in this separate file.
It is a bit cleaner this way but I dont have much preference
@@ -6,6 +6,7 @@ import ( | |||
"os" | |||
|
|||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | |||
_ "github.com/shapeshift/unchained-cosmos/docs/cosmos" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to import this in main even if its unused so that go-swagger can see it
log.Infof("invoking ListenAndServe on %s", listenAddr) | ||
log.Errorf("ListenAndServe returned: %s", http.ListenAndServe(listenAddr, router)) | ||
log.Errorf("ListenAndServe returned: %s", http.ListenAndServe(listenAddr, handlers.CORS(credentials, methods, origins)(router))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add cors stuff so calls from the swagger doc server would work
Balance string `json:"balance"` | ||
Tokens []TokenAmount `json:"tokens"` | ||
Delegations []Delegation `json:"delegations"` | ||
// Example: cosmos1fx4jwv3aalxqwmrpymn34l582lnehr3eqwuz9e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how example values are populated in go-swagger
go-swagger annotations for account & txs endpoints