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


Golang Utils.Debugf方法代码示例

本文整理汇总了Golang中github.com/daohoangson/go-socialcounters/utils.Utils.Debugf方法的典型用法代码示例。如果您正苦于以下问题:Golang Utils.Debugf方法的具体用法?Golang Utils.Debugf怎么用?Golang Utils.Debugf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/daohoangson/go-socialcounters/utils.Utils的用法示例。


在下文中一共展示了Utils.Debugf方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: googleLegacy

func googleLegacy(u utils.Utils, url string) result {
	start := time.Now()
	var res result

	urlJson, err := json.Marshal(url)
	if err != nil {
		res.Error = err
		return res
	}

	// http://bradsknutson.com/blog/get-google-share-count-url/
	body := `[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":` + string(urlJson) + `,"source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]`
	req, err := http.NewRequest("POST", "https://clients6.google.com/rpc", bytes.NewBufferString(body))
	if err != nil {
		res.Error = err
		return res
	}

	utils.Verbosef(u, "Calling http.Client.Do(body=%s)", body)
	req.Header.Set("Content-Type", "application/json")
	resp, err := u.HttpClient().Do(req)
	if err != nil {
		res.Error = err
		return res
	}

	defer resp.Body.Close()
	respBody, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		res.Error = err
		return res
	}
	res.Response = respBody
	u.Debugf("googleLegacy(url=%s) took %s", url, time.Since(start))

	jsonparser.ArrayEach(respBody, func(element []byte, _ jsonparser.ValueType, _ int, err error) {
		if err != nil {
			res.Error = err
			return
		}

		if count, err := jsonparser.GetFloat(element, "result", "metadata", "globalCounts", "count"); err != nil {
			res.Error = err
			return
		} else {
			res.Count = int64(count)
		}
	})

	return res
}
开发者ID:daohoangson,项目名称:go-socialcounters,代码行数:51,代码来源:google.go

示例2: facebookWorker

func facebookWorker(u utils.Utils, req *request) {
	start := time.Now()
	urls := strings.Join(req.Urls, ",")
	url := prepareFbGraphUrl(u, urls)
	utils.Verbosef(u, "Calling http.Client.Get(%s)", url)

	resp, err := u.HttpClient().Get(url)
	if err != nil {
		req.Error = err
		return
	}

	defer resp.Body.Close()
	respBody, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		req.Error = err
		return
	}
	req.Response = respBody
	u.Debugf("facebookWorker(urls=%s) took %s", urls, time.Since(start))

	for _, url := range req.Urls {
		var res result

		if respUrl, _, _, err := jsonparser.Get(respBody, url); err != nil {
			res.Error = err
			res.Response = respBody
		} else {
			res.Response = respUrl
			if shareCount, err := jsonparser.GetInt(respUrl, "share", "share_count"); err != nil {
				// it's alright, for new urls Facebook does not return share.share_count at all
				res.Count = COUNT_INITIAL_VALUE
			} else {
				res.Count = shareCount
			}
		}

		req.Results[url] = res
	}

	return
}
开发者ID:daohoangson,项目名称:go-socialcounters,代码行数:42,代码来源:facebook.go

示例3: twitterLegacy

func twitterLegacy(u utils.Utils, url string) result {
	var res result
	start := time.Now()
	oscUrl := "http://opensharecount.com/count.json?url=" + neturl.QueryEscape(url)
	utils.Verbosef(u, "Calling http.Client.Get(%s)", oscUrl)

	resp, err := u.HttpClient().Get(oscUrl)
	if err != nil {
		res.Error = err
		return res
	}

	defer resp.Body.Close()
	respBody, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		res.Error = err
		return res
	}
	res.Response = respBody
	u.Debugf("twitterLegacy(url=%s) took %s", url, time.Since(start))

	if count, err := jsonparser.GetInt(respBody, "count"); err != nil {
		res.Error = err
		return res
	} else {
		if count == 0 {
			if oscError, err := jsonparser.GetString(respBody, "error"); err != nil {
				res.Error = errors.New(oscError)
				return res
			}
		}

		res.Count = count
	}

	return res
}
开发者ID:daohoangson,项目名称:go-socialcounters,代码行数:37,代码来源:twitter.go

示例4: RulesAllowUrl

func RulesAllowUrl(u utils.Utils, url string) bool {
	if !getBasic().MatchString(url) {
		u.Debugf("web.RulesAllowUrl: %s is not a valid url", url)
		return false
	}

	if wl := getWhitelist(u, false); wl != nil {
		if !wl.MatchString(url) {
			u.Debugf("web.RulesAllowUrl: %s is not whitelisted", url)
			return false
		}
	}

	if bl := getBlacklist(u, false); bl != nil {
		if bl.MatchString(url) {
			u.Debugf("web.RulesAllowUrl: %s is blacklisted", url)
			return false
		}
	}

	return true
}
开发者ID:daohoangson,项目名称:go-socialcounters,代码行数:22,代码来源:rules.go

示例5: RulesRefresh

func RulesRefresh(u utils.Utils) {
	getWhitelist(u, true)
	getBlacklist(u, true)

	u.Debugf("web.RulesReset ok")
}
开发者ID:daohoangson,项目名称:go-socialcounters,代码行数:6,代码来源:rules.go


注:本文中的github.com/daohoangson/go-socialcounters/utils.Utils.Debugf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。