當前位置: 首頁>>代碼示例>>Golang>>正文


Golang apihelper.NewAPIError函數代碼示例

本文整理匯總了Golang中ribbitrewardswalletandblockchainapi/apihelper.NewAPIError函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewAPIError函數的具體用法?Golang NewAPIError怎麽用?Golang NewAPIError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewAPIError函數的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
}
開發者ID:synrg-labs,項目名稱:Ribbit-API-docs,代碼行數:65,代碼來源:Client.go

示例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
}
開發者ID:synrg-labs,項目名稱:Ribbit-API-docs,代碼行數:53,代碼來源:Client.go


注:本文中的ribbitrewardswalletandblockchainapi/apihelper.NewAPIError函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。