dongyuan8312 2014-07-25 13:37
浏览 90
已采纳

在config.json文件中输入自定义类型值

I'm trying to use this forum software written in Go that has a config file that requires the values you see in main.go below. I tried to use an empty string "" for the oauth credentials to play around on my local machine but I got an error

json. json: cannot unmarshal string into Go value of type oauth.Credentials

So, even if I were to deploy it on a server, I thought I would have had to enter the credentials as a string, which would trigger the error there as well.

Assuming my api key and secret were like this

key= X482xYAFG1I2RKBYR
secret = 4929390593pqI4wNMljlj4N71oyOdlWCzyNKhv4BAd4QXLvW2LF

Taking into consideration the requirements from main.go below, how would you enter the credentials in a config.json file like this

{
    "TwitterOAuthCredentials":,
    "CookieAuthKeyHexStr":"2ded82bb63514dbd6a0af42a25df235c",
    "CookieEncrKeyHexStr":"4add93d1d6bb3489c9b3ab5448704068",
    "AnalyticsCode":"",
    "AwsAccess":"",
    "AwsSecret":"",
    "S3BackupBucket":"",
    "S3BackupDir": ""
}

config requirements from main.go

config = struct {
    TwitterOAuthCredentials *oauth.Credentials
    CookieAuthKeyHexStr     *string
    CookieEncrKeyHexStr     *string
    AnalyticsCode           *string
    AwsAccess               *string
    AwsSecret               *string
    S3BackupBucket          *string
    S3BackupDir             *string
}{
    &oauthClient.Credentials,
    nil, nil,
    nil,
    nil, nil,
    nil, nil,
}
  • 写回答

1条回答 默认 最新

  • dtc99987 2014-07-25 13:47
    关注

    If you don't want to set it, leave it out entirely, and it will get set to the default value.

    Otherwise, enter the json representation of an oauth.Credentials, which is just a Token and a Secret string:

    type Credentials struct {
        Token  string // Also known as consumer key or access token.
        Secret string // Also known as consumer secret or access token secret.
    }
    

    In your config, the credentials would look like:

    "TwitterOAuthCredentials": {
        "Token": "oauthtoken",
        "Secret": "oauthsecret"
    },
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)