英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论