示例#1
0
func lengthen(url string) (string, error) {
	svc, _ := urlshortener.New(http.DefaultClient)
	res, err := svc.Url.Get(url).Do()
	if err != nil {
		return "", err
	}
	return res.LongUrl, err
}
示例#2
0
func shorten(url string) (string, error) {
	// 使用http中的default client创建一个新的 urlshortener 实例
	svc, _ := urlshortener.New(http.DefaultClient)
	res, err := svc.Url.Insert(&urlshortener.Url{LongUrl: url}).Do()
	if err != nil {
		return "", err
	}
	return res.Id, err
}