dongmeixi5311 2014-05-18 12:03
浏览 154
已采纳

在go二进制文件中包含模板/ html文件

Loving Go's built-in template libraries, currently I am just declaring the template as const string. How does one normally go about including larger more sophisticated template files? Ideally I prefer them to be inside the binary to simplify deployment.

  • 写回答

3条回答 默认 最新

  • doudunyi3796 2014-05-18 13:13
    关注

    There is no standard way to do this in Go.

    As comments show there is a few libraries available that will help you transform binary data (like templates, images eg.) to Go source files that can be compiled with your own source files to the final binary.

    Although this approach works for many projects I will recommend you reconsider. The cost of having easy distribution is that you must re-generate the source files creating assets before compiling the main source code and when you want to distribute a minor change to the templates/javascript/images&eg. included this way you will have to re-compile and restart the whole server.

    On most projects I've worked on changes in frontend stuff is by far the most frequent kind of change - which caused us to move away from this practice.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料