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"
    },
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路