<p>I'm new to go, coming mainly from Python. I wanted to know if there are any REST API frameworks that generate the API documentation as you build the code. The best example of this is <a href="http://www.django-rest-framework.org/">django-rest-framework</a>, <a href="http://flask-restful-swagger.readthedocs.io/en/latest/">flask-restful-swagger</a>, and my new favorite, <a href="https://github.com/encode/apistar/blob/master/README.md">apistar</a>. </p>
<p>I know about [swagger codegen]() which can generate go server code from an api specification, but that is pretty basic and you end up having to edit the code after you generate it. I'm looking to have the spec generated as a result of the code.</p>
<hr/>**评论:**<br/><br/>deranjer: <pre><p>I don't know of anything that does exactly what you are looking for. I haven't used it myself but GOA <a href="https://github.com/goadesign/goa" rel="nofollow">https://github.com/goadesign/goa</a> apparently has a DSL that you design that generates a swagger spec for you, as well as some code generation. That is the closest I know of.</p></pre>soawesomejohn: <pre><p>Thanks, this looks pretty solid. It's a different approach, but not a bad one.</p></pre>HugoWeb: <pre><p>IMHO you won't be happy with Go if you want to mimic Python in that regard :(</p></pre>soawesomejohn: <pre><p>Thanks for the honest response. I have mainly been interested in Go for doing some command line tools and eventually some desktop GUI programs.</p>
<p>I just know that there are some decent Go web frameworks such as Revel and Gin. Go has strong typing support. I could definitely see a framework able to do self inspection of its router and required parameters/arguments to produce an api reference. </p></pre>deranjer: <pre><p>Just curious what your plan was for desktop gui programs? Support for desktop gui seems like it is mainly binding to some other gui library, nothing native to go. Not saying that python is any better since I used python for a desktop gui app once and decided it just wasnt the best way to do it.</p></pre>soawesomejohn: <pre><p>What I've seen is all for bindings as well. GUIs I'm thinking of would be add-ons to command line utilities, geared towards controlling local hardware or amateur radio communications. I want them to be relatively lean, and I'm planning to avoid the browser shell/electron route.</p>
<p>The one that I was most interested in is <a href="https://github.com/andlabs/ui" rel="nofollow">ui</a>/<a href="https://github.com/andlabs/libui" rel="nofollow">libui</a>, but the development of that is (understandably) slow. It still might be worth experimenting with because it looks like it would be pretty clean and lightweight. </p>
<p>Otherwise, the top contenders are Qt and <a href="https://github.com/vurtun/nuklear" rel="nofollow">Nuklear</a>. Qt seems like the best choice, though it does have some licensing restrictions around distribution that complicates things. </p></pre>HugoWeb: <pre><p>I love Golang for command line/text tools!
And there are lots of libraries like <a href="https://github.com/rivo/tview" rel="nofollow">https://github.com/rivo/tview</a> for playing.</p></pre>Jlocke98: <pre><p>It is a best practice in software development to have a rigorously defined API and then coding to that specification, not the other way around. If you don't like swagger, then you might prefer protobufs and gRPC. </p></pre>govision: <pre><p>Well it's not as you code but I think code is for coding and documentation is for documenting.
Godoc makes use of commenting as part of it's implemention.</p>
<p><a href="https://www.ardanlabs.com/blog/2013/06/documenting-go-code-with-godoc.html" rel="nofollow">https://www.ardanlabs.com/blog/2013/06/documenting-go-code-with-godoc.html</a></p></pre>jamesrr39: <pre><p>Chi[1] has a markdown & JSON doc generation tool. There's an example of it in use at <a href="https://github.com/go-chi/chi/blob/4c5a584b324b74af3e9cfeaf6265d14ae2fdfc99/_examples/rest/main.go" rel="nofollow">https://github.com/go-chi/chi/blob/4c5a584b324b74af3e9cfeaf6265d14ae2fdfc99/_examples/rest/main.go</a></p>
<ol>
<li><a href="https://github.com/go-chi/chi" rel="nofollow">https://github.com/go-chi/chi</a></li>
</ol></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传