Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

go-swagger example from source #3

wants to merge 1 commit into from

Conversation

elmutt
Copy link
Contributor

@elmutt elmutt commented Dec 15, 2021

go-swagger annotations for account & txs endpoints

"github.com/shapeshift/unchained-cosmos/service"
)

// swagger:route GET /account/{pubkey} account-tag accountEndpointId
Copy link
Contributor Author

@elmutt elmutt Dec 15, 2021

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"
Copy link
Contributor Author

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)))
Copy link
Contributor Author

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant