如何创建一个包含zoneinfo.zip的二进制文件 [英] How to create a binary that contains zoneinfo.zip

查看:106
本文介绍了如何创建一个包含zoneinfo.zip的二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Docker创建容器应用程序,然后将其部署到 kubernetes引擎但是在初始化应用程序时出现此错误:

I'm using Docker to create a container application and then deploy it to kubernetes engine but when the application is been initialized I get this error:

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

推荐答案

在使用Go的时间包,特别是LoadLocation方法时,它将查找时区数据库在各个位置的信息.在 https://golang.org/src的源代码中对LoadLocation的注释中对此进行了解释. /time/zoneinfo.go .具体来说,它会在以下位置显示:

When using Go's time package, specifically the LoadLocation method, it looks for time zone database information in various locations. This is explained in the comments for LoadLocation in the source code at https://golang.org/src/time/zoneinfo.go. Specifically it looks in these places:

  1. ZONEINFO环境变量指定的位置
  2. 时区数据库文件保存在Unix操作系统上的已知位置
  3. $ GOROOT中的zoneinfo.zip文件

在Windows机器上编程时,Go很可能默认为第3个选项.但是,使用二进制文件时没有$ GOROOT,因此在您的容器中不起作用.在大多数版本的Linux上,第二个选项可以正常工作,因为它们具有必需的时区数据库文件.但是,我强烈怀疑您引用的优化容器没有.这为您提供了选项1,该选项实质上包括将您自己的时区数据库文件放在容器上,然后使用ZONEINFO环境变量引用它们的位置.这既使人感到痛苦,也发现当您请求不存在的时区文件时,它会以静默方式失败.

When you're programming on a Windows machine, Go is most likely defaulting to the 3rd option. However, there is no $GOROOT when you're working with a binary, so that won't work in your container. On most versions of Linux the 2nd option would work fine as they would have the necessary time zone database files. However, I have a strong suspicion that the optimized container you reference does not. This leaves you with option 1, which essentially consists of putting your own time zone database files on the container and then referencing their location with the ZONEINFO environment variable. This is both kind of a pain in the ass and I've also found that it fails silently when you request a time zone file that doesn't exist.

我自己解决了这个问题,最终创建了一个使用LoadLocationFromTZData方法的程序包,并试图简化提供和使用自己的时区数据库副本的过程.您可以在这里看到我自己的堆栈溢出问题:检测ZONEINFO是否在Go中失败 .您可以在此处查看我的时区包的存储库: https://github.com/slotheroo/knozone

In my own addressing of this problem I ended up creating a package that utilizes the LoadLocationFromTZData method and tries to simplify the process of providing and working with your own copy of the time zone database. You can see my own stack overflow question here: Detect if ZONEINFO fails in Go. And you can see the repository for my time zone package here: https://github.com/slotheroo/knozone

这篇关于如何创建一个包含zoneinfo.zip的二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆