<p>I have been working on a todo list manager since quite some time now. It started as a simple text storing application and now includes few good features which I feel are useful like github flavoured markdown</p>
<p><a href="https://github.com/thewhitetulip/Tasks">https://github.com/thewhitetulip/Tasks</a></p>
<hr/>**评论:**<br/><br/>IFupvoteTHENsendNUDE: <pre><p>First of all, the front-end work is great. I'm used to programming in Python for back-end. I've just started to learn Go and I want to build web applications with it. Did you find it hard build it? I'm reading your code(first web app I've seem) and seem's pretty clean, more than I would have expected before.</p></pre>thewhitetulip: <pre><p>If you are interested, I am writing a book on writing webapps with Go.</p>
<p><a href="https://github.com/thewhitetulip/web-dev-golang-anti-textbook/" rel="nofollow">https://github.com/thewhitetulip/web-dev-golang-anti-textbook/</a></p>
<p>Thank you! I had worked on the front end for a long time, github.com/thewhitetulip/omninotesweb.</p>
<p>I love UX/UI equally along with backend :)</p></pre>IFupvoteTHENsendNUDE: <pre><p>Such a great work. Starred.</p>
<p>I'll take a look in the details later. Thanks!</p></pre>thewhitetulip: <pre><p>Thank you!! I am happy that I am helping someone :-)
I face a lot of problems while writing this app</p></pre>schoenobates: <pre><p>Very nice - good work</p></pre>thewhitetulip: <pre><p>Thank you :-) any improvements I can do?</p></pre>skarlso: <pre><p>Hey man.</p>
<p>This is solid work. I like the front-end. :) Very good stuff. Where did you learn to do that? :) I'm lacking a good front-end design skill. Though I'm going to take codeacademy's tutorial on that. :)</p>
<p>Some things you could improve in regards to coding -> </p>
<ul>
<li>When working with Json use Decoder. It will make handling json a lot easier. </li>
<li>Some of your error cases are not returning a http.StatusNotFound or whatever. Like in deleteviews -> log.Println(err) -> After this a nice return error code should be set</li>
<li>Most of your error handling in deleteViews can be abstracted out into a common function, call it handleError and give it a writer. You could skip most of the ifs.</li>
<li>DB:
<ul>
<li>On Add file you are ignoring the error when the DB doesn't begin -> tx, err := database.Begin() -> you do log it but then don't do a return err. Or is this intentional?</li>
<li>You have a lot of other places where you simply continue on an error and don't do return err. Is that intentional?</li>
<li>I would extract database into a type where you can share the connection. That way a lot of this -> database.Begin() could be eliminated since the type would handle connection with a pointer receiver. Basically a database singleton.</li>
<li>Also, create a rollback conditional defer. If err != nil -> rollback. They way you can skip a lot of ifs and error handling into a single pointer receiver function.</li>
</ul></li>
</ul>
<p>Hope this helps. This is a very quick overview of the code.</p>
<p>Well done! :)</p></pre>thewhitetulip: <pre><p>Thanks a lot!! I learnt front end dev by myself :-)
Json decoder? I have no idea what it is.</p>
<p>returning errors, yes, I am going to do that soon, two things are left in the application as of now, sessions & categories</p>
<p>About HandleErrors, I have read at many posts that rather than an abstracted function the <code>if err != nil</code> is more Goish.</p>
<p>About rollback, yes I don't know how I missed it!</p>
<p>Also a lot of placed I don't do anything on error because errors shouldn't happen there :-) like the database query things, the reason being the program won't compile if there is an error at that stage. Also it isn't intentional, the thing is when I started writing the application it was from scratch, so I put the print statements to log errors, I am yet to formulate a mechanism to notify about the error to the actual users via template rendering.</p>
<p>Thank you for your comment :)</p></pre>skarlso: <pre><p>Ahh gotcha. :-) Error popups to the rescue. </p>
<p>The json stuff is not that important since you are not posting anything with a json body. You are only using json in the configuration. The decoder handles closing reader bodies, that's why it's convenient. </p>
<p>Like this:</p>
<pre><code>decoder :=json.NewDecoder(req.Body)
var t test_struct
err := decoder.Decode(&t)
if err != nil {
panic()
}
log.Println(t.Test)
</code></pre>
<p>This way you don't have to deal with io. ReadAll or something similar. </p>
<p>The app <em>does</em> look very neat. :-) </p></pre>thewhitetulip: <pre><p>thank you!!</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传