gpt4 book ai didi

go - 如何创建包含 zoneinfo.zip 的二进制文件

转载 作者:IT王子 更新时间:2023-10-29 02:01:24 28 4
gpt4 key购买 nike

我正在使用 Docker 创建容器应用程序,然后将其部署到 kubernetes engine但是当应用程序被初始化时,我得到这个错误:

err: open C:\Go/lib/time/zoneinfo.zip: no such file or directory

enter image description here

enter image description here

最佳答案

您可能会考虑构建您的 Go 应用程序 with Go 1.15 (2020 年 8 月,两年后)

New embedded tzdata package

Go 1.15 includes a new package, time/tzdata, that permits embedding the timezone database into a program.

  • Importing this package (as import _ "time/tzdata") permits the program to find timezone information even if the timezone database is not available on the local system.
  • You can also embed the timezone database by building with -tags timetzdata.

Either approach increases the size of the program by about 800 KB.

这样,一旦作为 Docker 镜像部署到 Kubernetes 引擎,它就不必尝试加载任何时区信息,因为这些信息已嵌入其程序中。

注意:如commented通过 dolmen :

This solution has the drawback that the timezone information version is linked to the version of Go you use for building.

If you keep using a fixed version of Go for your project, you will keep timezones from that version.

Being able to update the timezone information independently from the Go version (update every time you rebuild the Docker image for deploy) might be a better choice.

作为示例,请参见支石墓的 answer .

关于go - 如何创建包含 zoneinfo.zip 的二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52489347/

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