不能在返回参数中使用错误(类型错误)作为类型goreq.Error

时间:2015-04-15 19:09:34

标签: go

我试图从方法返回两个值(结果和错误),但我得到了这个

cannot use err (type error) as type goreq.Error in return argument

我的代码

package components

import (
    goreq "github.com/franela/goreq"
    "time"
)

var UserAgent string = "..."

func Get(url string) (*goreq.Response, goreq.Error) {
    goreq.SetConnectTimeout(15 * time.Second)
    res, err := goreq.Request{
        Uri: url,
        UserAgent: UserAgent,
        Timeout: 5 * time.Second,
    }.Do()

    return res, err
}

1 个答案:

答案 0 :(得分:3)

Do() returns type error, not goreq.Error。将您的第二次回复类型更改为error,而不是goreq.Error