Documentation ¶
Overview ¶
Package rest provides HTTP types and primitives for REST requests validation and responses handling.
Index ¶
- func ParseFloat64OrReturnBadRequest(w http.ResponseWriter, s string, defaultIfEmpty float64) (n float64, ok bool)
- func ParseInt64OrReturnBadRequest(w http.ResponseWriter, s string) (n int64, ok bool)
- func ParseUint64OrReturnBadRequest(w http.ResponseWriter, s string) (n uint64, ok bool)
- func PostProcessResponse(w http.ResponseWriter, cdc *codec.Codec, response interface{}, indent bool)
- func ReadRESTReq(w http.ResponseWriter, r *http.Request, cdc *codec.Codec, req interface{}) bool
- func WriteErrorResponse(w http.ResponseWriter, status int, err string)
- func WriteSimulationResponse(w http.ResponseWriter, cdc *codec.Codec, gas uint64)
- type BaseReq
- type ErrorResponse
- type GasEstimateResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseFloat64OrReturnBadRequest ¶
func ParseFloat64OrReturnBadRequest(w http.ResponseWriter, s string, defaultIfEmpty float64) (n float64, ok bool)
ParseFloat64OrReturnBadRequest converts s to a float64 value. It returns a default value, defaultIfEmpty, if the string is empty.
func ParseInt64OrReturnBadRequest ¶
func ParseInt64OrReturnBadRequest(w http.ResponseWriter, s string) (n int64, ok bool)
ParseInt64OrReturnBadRequest converts s to a int64 value.
func ParseUint64OrReturnBadRequest ¶
func ParseUint64OrReturnBadRequest(w http.ResponseWriter, s string) (n uint64, ok bool)
ParseUint64OrReturnBadRequest converts s to a uint64 value.
func PostProcessResponse ¶
func PostProcessResponse(w http.ResponseWriter, cdc *codec.Codec, response interface{}, indent bool)
PostProcessResponse performs post processing for a REST response.
func ReadRESTReq ¶
ReadRESTReq reads and unmarshals a Request's body to the the BaseReq stuct. Writes an error response to ResponseWriter and returns true if errors occurred.
func WriteErrorResponse ¶
func WriteErrorResponse(w http.ResponseWriter, status int, err string)
WriteErrorResponse prepares and writes a HTTP error given a status code and an error message.
func WriteSimulationResponse ¶
func WriteSimulationResponse(w http.ResponseWriter, cdc *codec.Codec, gas uint64)
WriteSimulationResponse prepares and writes an HTTP response for transactions simulations.
Types ¶
type BaseReq ¶
type BaseReq struct { From string `json:"from"` Password string `json:"password"` Memo string `json:"memo"` ChainID string `json:"chain_id"` AccountNumber uint64 `json:"account_number"` Sequence uint64 `json:"sequence"` Fees sdk.Coins `json:"fees"` GasPrices sdk.DecCoins `json:"gas_prices"` Gas string `json:"gas"` GasAdjustment string `json:"gas_adjustment"` GenerateOnly bool `json:"generate_only"` Simulate bool `json:"simulate"` }
BaseReq defines a structure that can be embedded in other request structures that all share common "base" fields.
func NewBaseReq ¶
func NewBaseReq( from, password, memo, chainID string, gas, gasAdjustment string, accNumber, seq uint64, fees sdk.Coins, gasPrices sdk.DecCoins, genOnly, simulate bool, ) BaseReq
NewBaseReq creates a new basic request instance and sanitizes its values
func (BaseReq) ValidateBasic ¶
func (br BaseReq) ValidateBasic(w http.ResponseWriter) bool
ValidateBasic performs basic validation of a BaseReq. If custom validation logic is needed, the implementing request handler should perform those checks manually.
type ErrorResponse ¶
ErrorResponse defines the attributes of a JSON error response.
func NewErrorResponse ¶
func NewErrorResponse(code int, msg string) ErrorResponse
NewErrorResponse creates a new ErrorResponse instance.
type GasEstimateResponse ¶
type GasEstimateResponse struct {
GasEstimate uint64 `json:"gas_estimate"`
}
GasEstimateResponse defines a response definition for tx gas estimation.