gin with bindata templates+static files

polaris · · 1780 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m trying to package all the static and template files into a binary and trying it with gin at first.</p> <p>I&#39;m trying to follow the following example</p> <p><a href="https://github.com/gin-gonic/contrib/blob/master/static/example/bindata/example.go" rel="nofollow">https://github.com/gin-gonic/contrib/blob/master/static/example/bindata/example.go</a></p> <p>When I run it to the /ping url I just get &#34;test&#34; back and not the template at all. </p> <p>Is there a good working example of getting templates working with bindata and gin or should I switch to a new framework?</p> <p>thanks!</p> <p>Edit for code update</p> <p><a href="https://gist.github.com/mzupan/4881251f6e1a55a6dc76" rel="nofollow">https://gist.github.com/mzupan/4881251f6e1a55a6dc76</a></p> <p>The main issue i&#39;m having is when i hit /index foo.html doesn&#39;t work but /bar does I guess the SetHTMLTemplate is overwritting.. so I&#39;m a bit unsure of how to pass many templates into it</p> <hr/>**评论:**<br/><br/>miko5054: <pre><p>Show us some code :)</p></pre>hijinks: <pre><p>thanks.. I updated with a gist of the code sample</p></pre>giant_pollo: <pre><p>In your example gist, you&#39;re overwritting the template for index.html with a new template (which happends to be bar.html) on line 34. You should make a new, but empty template, to which you add the templates for index and bar. See <a href="https://github.com/GeertJohan/go.rice/issues/71" rel="nofollow">this issue</a> for an example. Notice the difference between &#34;template&#34; (the library) and &#34;templates&#34; (empty template which holds the other templates).</p> <p>In your example gist, you&#39;re overwritting the template for index.html with a new template (which happends to be bar.html) on line 34. You should make a new, but empty template, to which you add the templates for index and bar. See <a href="https://github.com/GeertJohan/go.rice/issues/71" rel="nofollow">this issue</a> for an example. Notice the difference between &#34;template&#34; (the library) and &#34;templates&#34; (empty template which holds the other templates).</p> <p>Edit: You should also know that most of the bindata like libraries seems to the unstable and not suitable for production. I read up on the libraries from <a href="https://github.com/avelino/awesome-go#resource-embedding" rel="nofollow">this list</a> and discovered that there was at least a major bug (major bug as in: infinite loop when acessing a dir, can only access one dir of many or not handling errors in a proper way are some examples) for each. Unfortunately I didn&#39;t take notes so I can&#39;t really give you examples.. My advice is to avoid trying to embed resources like this and let the libraries sort out their bugs first.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1780 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传