本文整理匯總了Golang中ribbitrewardswalletandblockchainapi/apihelper.CleanUrl函數的典型用法代碼示例。如果您正苦於以下問題:Golang CleanUrl函數的具體用法?Golang CleanUrl怎麽用?Golang CleanUrl使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CleanUrl函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetAddress
/**
* TODO: type endpoint description here
* @param string address parameter: Required
* @return Returns the *models.Address response from the API call
*/
func (me *DIGIBYTE_IMPL) GetAddress(
address string) (*models.Address, error) {
//the base uri for api requests
queryBuilder := ribbitrewardswalletandblockchainapi.BASEURI
//prepare query string for API call
queryBuilder = queryBuilder + "/api/digibyte/api/addr"
//variable to hold errors
var err error = nil
//process optional query parameters
queryBuilder, err = apihelper.AppendUrlWithQueryParameters(queryBuilder, map[string]interface{}{
"address": address,
})
if err != nil {
//error in query param handling
return nil, err
}
//validate and preprocess url
queryBuilder, err = apihelper.CleanUrl(queryBuilder)
if err != nil {
//error in url validation or cleaning
return nil, err
}
//prepare headers for the outgoing request
headers := map[string]interface{}{
"user-agent": "APIMATIC 2.0",
}
//prepare API request
request := unirest.Get(queryBuilder, headers)
//and invoke the API call request to fetch the response
response, err := unirest.AsString(request)
if err != nil {
//error in API invocation
return nil, err
}
//error handling using HTTP status codes
if (response.Code < 200) || (response.Code > 206) { //[200,206] = HTTP OK
err = apihelper.NewAPIError("HTTP Response Not OK", response.Code, response.RawBody)
}
if err != nil {
//error detected in status code validation
return nil, err
}
//returning the response
var retVal *models.Address = &models.Address{}
err = json.Unmarshal(response.RawBody, &retVal)
if err != nil {
//error in parsing
return nil, err
}
return retVal, nil
}
示例2: CreateBroadcastTransaction
/**
* TODO: type endpoint description here
* @return Returns the *models.BroadcastTransactionResponse response from the API call
*/
func (me *RIBBITREWARDS_IMPL) CreateBroadcastTransaction() (*models.BroadcastTransactionResponse, error) {
//the base uri for api requests
queryBuilder := ribbitrewardswalletandblockchainapi.BASEURI
//prepare query string for API call
queryBuilder = queryBuilder + "/api/ribbit/api/tx"
//variable to hold errors
var err error = nil
//validate and preprocess url
queryBuilder, err = apihelper.CleanUrl(queryBuilder)
if err != nil {
//error in url validation or cleaning
return nil, err
}
//prepare headers for the outgoing request
headers := map[string]interface{}{
"user-agent": "APIMATIC 2.0",
}
//prepare API request
request := unirest.Post(queryBuilder, headers)
//and invoke the API call request to fetch the response
response, err := unirest.AsString(request)
if err != nil {
//error in API invocation
return nil, err
}
//error handling using HTTP status codes
if (response.Code < 200) || (response.Code > 206) { //[200,206] = HTTP OK
err = apihelper.NewAPIError("HTTP Response Not OK", response.Code, response.RawBody)
}
if err != nil {
//error detected in status code validation
return nil, err
}
//returning the response
var retVal *models.BroadcastTransactionResponse = &models.BroadcastTransactionResponse{}
err = json.Unmarshal(response.RawBody, &retVal)
if err != nil {
//error in parsing
return nil, err
}
return retVal, nil
}