将JSON文件作为配置文件。

huangapple go评论83阅读模式
英文:

JSON file as config

问题

我有一个JSON文件作为配置。我可能遇到的问题是它无法在Go中编译,我担心这也可能影响应用程序的性能,因为每个请求都要导入JSON。如果我使用Struct并在单独的Go文件中初始化它,会更好吗?

英文:

I have JSON file as config. The problem I may see is that this cannot be compiled in Go and I'm worried that this also might affect the performance of the application since JSON is imported for every request. Would I be better off using Struct and initialising it in a separate Go file?

答案1

得分: 0

如果您可以存储配置的Go代码,那么我假设在应用程序执行期间配置不会发生变化。在应用程序启动时加载配置,并将解析后的表示存储在内存中,可能是从包级别变量引用。

英文:

If you can store the configuration Go code, then I assume that the configuration does not change during the execution of the application. Load the configuration when the application starts and store the parsed representation in memory, possibly referenced from a package level variable.

huangapple
  • 本文由 发表于 2014年10月15日 22:25:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/26385012.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定