Feedback on my twitch irc library

polaris · · 434 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hey,</p> <p>I&#39;ve been writing some Go in the past 2 years in my free time, but I&#39;ve stayed very basic, because I just don&#39;t have the time for much more.</p> <p>I wrote this library a few months ago and was wondering if I could get some feedback on it.</p> <p>You could use this library to e.g. write a twitch bot.</p> <p><a href="https://github.com/gempir/go-twitch-irc">https://github.com/gempir/go-twitch-irc</a></p> <p>I&#39;ve tried getting code coverage as high as possible, but I&#39;m really unsure how I correctly test the IRC part of my client.</p> <hr/>**评论:**<br/><br/>ShawnSmith08: <pre><p>Your code looks pretty good, but it looks like you&#39;re only allowing for one callback function per OnMessage.</p> <p>You could turn that into an slice of functions and iterate over the slice to call each function.</p> <p>You could also play with nested maps like map[string]map[int]func(). So the map would look like [&#34;OnMessage&#34;][0]callBackFunc(1), [&#34;OnMessage&#34;][1]callBackFunc(2), etc.</p></pre>gempir: <pre><p>What&#39;s the usecase there though. I&#39;d rather have the user implement 1 function and then just use a channel to share the messages with other functions. </p></pre>allhatenocattle: <pre><p>Overall pretty good. A couple of minor nits:</p> <p><a href="https://github.com/gempir/go-twitch-irc/blob/master/client.go#L14" rel="nofollow">https://github.com/gempir/go-twitch-irc/blob/master/client.go#L14</a> naming is typically camelCase and this doesn&#39;t need to be exported so switch to ircTwitch</p> <p><a href="https://github.com/gempir/go-twitch-irc/blob/master/client.go#L73" rel="nofollow">https://github.com/gempir/go-twitch-irc/blob/master/client.go#L73</a> printing conn when there was an error calling dial(), it is almost certainly going to be empty</p> <p><a href="https://github.com/gempir/go-twitch-irc/blob/master/client.go#L96" rel="nofollow">https://github.com/gempir/go-twitch-irc/blob/master/client.go#L96</a> If len(messages) is zero, the range statement on L99 won&#39;t do anything so this check isn&#39;t needed</p> <p><a href="https://github.com/gempir/go-twitch-irc/blob/master/client.go#L109-L110" rel="nofollow">https://github.com/gempir/go-twitch-irc/blob/master/client.go#L109-L110</a> why use fmt.Sprintf inside a fmt.Fprintf, can do it all with the beginning fmt.Fprintf</p> <p><a href="https://github.com/gempir/go-twitch-irc/blob/master/client.go#L126" rel="nofollow">https://github.com/gempir/go-twitch-irc/blob/master/client.go#L126</a> fmt.Sprintf() isn&#39;t needed, just use </p> <pre><code>c.send(strings.Replace(line, &#34;PING&#34;, &#34;PONG&#34;, 1)) </code></pre> <p><a href="https://github.com/gempir/go-twitch-irc/blob/master/client.go#L155" rel="nofollow">https://github.com/gempir/go-twitch-irc/blob/master/client.go#L155</a> break isn&#39;t needed since not in a loop</p> <p><a href="https://github.com/gempir/go-twitch-irc/blob/master/client.go#L169" rel="nofollow">https://github.com/gempir/go-twitch-irc/blob/master/client.go#L169</a> declare func(channel string, user User, message Message) as a type like callback and then the On*Message func definitions will look cleaner</p> <p>Cheers! edit - some additional notes</p></pre>shazow: <pre><p>Looks like you&#39;re doing your own IRC parsing/message composition. That&#39;s fine, but there are a few great libraries that help with that. I&#39;m a fan of <a href="https://github.com/sorcix/irc" rel="nofollow">https://github.com/sorcix/irc</a>, might save you some trouble with unexpected bugs.</p></pre>SpokenSpruce: <pre><p>Neither <code>master</code> nor the <code>v2</code> branch has ircv3 tags, which OP uses in their library. And IRC parsing is easy and testable enough that I&#39;d personally rather spend the 5-6 hours doing it than leave the maintenance and decision making to such a core component to a third party.</p></pre>gempir: <pre><p>Yeah I know a lib could do that for me but I have to parse custom twitch stuff anyway and I wanted a clean Lib without any dependencies</p> <p>So I just went with my online parser </p></pre>shazow: <pre><p>That&#39;s cool, good work! :)</p></pre>yamamushi: <pre><p>Glad you posted this! It will likely come in handy when I rewrite TwitchInstallsArchLinux in Golang and try to boot it up again. </p></pre>gempir: <pre><p>Oh you wrote that? Awesome, the idea was funny as hell </p></pre>yamamushi: <pre><p>I can&#39;t take all the credit for it, but it certainly was an experiment in sysadmin hell (they kept pulling up porn on the desktop, not to mention the DDoS).</p> <p>I look forward to using your library :) </p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

434 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传