dsd57259 2016-02-11 00:32
浏览 6
已采纳

净值/网址值出现错误{}

I am working on my first golang application. I am trying to take a url value through the router and push it along to a url which will make a POST request to a API. All of that works, but when I try to make query parameters to send with the POST request using the Value map from net/url I start to get errors.

Here is the relevant code:

package Utils

import (
    "fmt"
    "bytes"
    "encoding/json"
    "encoding/base64"
    "log"
    "net/http"
    "net/url"
    "io/ioutil"
)

...

func RetrieveAccessToken(client_id, client_secret, url, grant_type, code, redirect_uri string){
    // The data we are going to send with our request
    data := url.Values{}
    data.Set("client_id", client_id)
    data.Add("client_secret", client_secret)
    data.Add("grant_type", grant_type)
    data.Add("code", code)
    data.Add("redirect_uri", redirect_uri)

...

}

And here are the errors I am getting

Utils/Api.go:25:23: error: expected ‘;’ or ‘}’ or newline
data := url.Values{}
                  ^

After this error I get an error like this for every single line following the previous one:

Utils/Api.go:26:5: error: expected declaration
data.Set("client_id", client_id)
^

Until finally I get this error referencing that net/url Values call

Utils/Api.go:25:16: error: reference to undefined field or method ‘Values’
     data := url.Values{}
                ^

If anyone could help me figure this out I would be very grateful. I have been looking at the Go docs for awhile, and it seems like I have been following their examples pretty closely. If there is a rule I am misunderstanding, or something I am missing I would be very thankful if you could point me in the right direction!

Thanks again!

  • 写回答

1条回答 默认 最新

  • donoworuq450547191 2016-02-11 00:39
    关注

    You've shadowed the "url" package name with the url argument in your function. Rename the latter.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?