gpt4 book ai didi

grails - 在 grails 中存储 api 客户端 key 的位置

转载 作者:行者123 更新时间:2023-12-02 15:07:37 27 4
gpt4 key购买 nike

我想将 api key 存储在我的 grails 应用程序中。 Api key 应该是全局的,并且可以每隔几分钟或几小时更改一次。

全局存储此 key 的最佳位置在哪里?
我不想将它存储在数据库中,猜测配置是最好的地方。
但我认为 config 是存储常量而不是可变数据的好地方。

那么,在哪里全局存储 api key 呢?

更新:可能是带有静态字段的类,如 String apiKey会足够吗?

最佳答案

Api key should be global and can be changed every several minutes or hours.



为什么 API key 会如此频繁地更改?

guess that config is the best place. But I suppose that config is a good place to store constants, not changeable data.



通常属性在 Config.groovy是只读的,但没有什么可以阻止您修改它们,例如
class MyController {
def grailsApplication

def updateApiKey(String newKey) {
grailsApplication.config.apiKey = newKey
}
}

关于grails - 在 grails 中存储 api 客户端 key 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24259875/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com