<p>I'm trying to package all the static and template files into a binary and trying it with gin at first.</p>
<p>I'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 "test" 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'm having is when i hit /index foo.html doesn't work but /bar does I guess the SetHTMLTemplate is overwritting.. so I'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'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 "template" (the library) and "templates" (empty template which holds the other templates).</p>
<p>In your example gist, you'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 "template" (the library) and "templates" (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't take notes so I can'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
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传