当前位置: 首页>>代码示例>>Golang>>正文


Golang apihelper.CleanUrl函数代码示例

本文整理汇总了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
}
开发者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.CleanUrl函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。