Golang导入(未定义:请求)

Golang导入(未定义:请求)

问题描述:

I'm trying to create a custom function that passes the Request object back as a result:

 func ConstructRequest(testParameters string, reqType string) Request {
    req, err := http.NewRequest(reqType, testPath+testParameters, nil)

    if err != nil {
        log.Fatal(err)
        return nil
    } else {
        return req
    }
}

but I'm getting a "undefined: Request" error

I'm not sure what library I need to import to make it work?

我正在尝试创建一个自定义函数,从而将Request对象传递回: p> \ n

 函数func ConstructorRequest(testParameters字符串,reqType字符串)请求{
 req,err:= http.NewRequest(reqType,testPath + testParameters,nil)
 
如果err!= nil {\  n log.Fatal(err)
返回nil 
}否则{
返回要求
} 
} 
  code>  pre> 
 
 

,但是我得到一个“ 未定义:请求”错误 p>

我不确定需要导入哪个库才能使其正常工作? p> div>

undefined: Request seems normal if you don't specify the package for the returned type:

func ConstructRequest(testParameters string, reqType string) http.Request
                                                             ^^^^

Since http.NewRequest() returns a pointer, this should be:

func ConstructRequest(testParameters string, reqType string) *http.Request