<p>Hi guys. I'm a Python developer who is currently learning to write Go code. So I'm a total newbie to <strong>Golang</strong>.
I found interesting to work on a little project called <a href="https://github.com/Belekkk/gotoc" rel="nofollow">gotoc</a>. It is a tool made in <strong>Go</strong> to generate markdown table of contents inside a local git repo. Links generated refers to Github anchors.
I think that my code is dirty and I am searching some advices from experimented Go developers.
I will appreciate your help.</p>
<hr/>**评论:**<br/><br/>earthboundkid: <pre><p>Use gofmt.</p></pre>Redundancy_: <pre><p>Some ideas here: <a href="https://gist.github.com/Redundancy/89a5f490062fec3c84a0a4d0b1f9b05f" rel="nofollow">https://gist.github.com/Redundancy/89a5f490062fec3c84a0a4d0b1f9b05f</a></p>
<p>I removed the file manipulation from the main function to help make it testable, removed the multiple passes through the source file to reduce the length and complexity, brought in some buffers and TeeReader to make appending he original content easier (just a copy) and rely much more on io.WriterTo. The boolean variable is gone, replaced by just checking for an empty title, and that logic is moved into the title type, reducing the complexity of the main function. Some redundant assignments are gone.</p>
<p>I've changed the order to put the most important functions at the top and tried to make writeToc as readable as possible.</p>
<p>Some of the functionality has probably changed slightly, but it's hopefully fairly close to the original.</p></pre>belekkk: <pre><p>I will really appreciate your comment.
You have reduced the complexity and that's why I wanted.
I have to write some tests too.
Thank you ! </p></pre>
Newbie to Golang need some advices to develop a TOC generator for Markdown files
xuanbao · · 444 次点击这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传