<p>I'm looking for a tool that works similar to the go-restful swagger server:</p>
<p><a href="https://github.com/emicklei/go-restful/blob/master/examples/restful-swagger.go">https://github.com/emicklei/go-restful/blob/master/examples/restful-swagger.go</a></p>
<p>This tool is awesome because it's super easy to integrate with your web service and it automatically updates the swagger spec if/when you change your models. These are the two main reasons I don't use go-swagger.</p>
<p>However, the go-restful swagger server is tightly coupled to the go-restful library. I was wondering if a similar tool exists that isn't coupled to a particular web framework/package - ideally, something that works with the builtin http lib (e.g. it has a ServeHTTP(w, r) function).</p>
<p>Use case: I want the benefits of the go-restful swagger server, but be able to add it to any go web service I want. If I have services that run gorilla/mux, another on urfave/negroni, and another with just the standard http package - it would be nice to add swagger to these services with as little overhead as possible. </p>
<p>If this tool doesn't already exist - anyone want to build it with me?
I've thrown together some ideas for an api here: <a href="https://gist.github.com/zpatrick/d7be4ea99694e328498a430e65c06d84">https://gist.github.com/zpatrick/d7be4ea99694e328498a430e65c06d84</a></p>
<hr/>**评论:**<br/><br/>jgillich: <pre><p>What about go-swagger? It appears to be able to generate the swagger spec from code comments; sure, not as nice as generating from actual code, but pretty close.</p></pre>zpatrick319: <pre><p>True, but that also comes with the overhead of running swaggergen every time I make a change. A big win with the go-restful approach is that it does this at runtime. </p></pre>casualjim: <pre><p>go-swagger should support both use cases. you can generate a server (which is just middleware for the http lib) and then you can edit that code and generate a spec from it.
You could then use that spec to generate a server again which should be equivalent to what you had already</p></pre>zpatrick319: <pre><p>I touched on this in the original post, but go-swagger doesn't have the features I'm asking about. The go-restful plugin is a vast improvement for my use case because I don't need to worry about updating a json file or code comments every time I change a model. The server generation is not what I'm asking for - I'm talking about a plugin generates and serves the apidocs.json file at runtime, an serves the swagger ui. </p></pre>robbert229: <pre><p>Right now my team is using go-swagger and we love it! Only thing to keep in mind is that you should vendor your tools! ( we encountered issues early on because of it )</p></pre>andre_borges: <pre><p>beego framework have this feature, I think</p></pre>
Anyone know of a swagger server generator (like go-restful) that works with the builtin http lib?
xuanbao · · 498 次点击这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传