<p>Hey,</p>
<p>I've been writing some Go in the past 2 years in my free time, but I've stayed very basic, because I just don'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've tried getting code coverage as high as possible, but I'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'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 ["OnMessage"][0]callBackFunc(1), ["OnMessage"][1]callBackFunc(2), etc.</p></pre>gempir: <pre><p>What's the usecase there though. I'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'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't do anything so this check isn'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't needed, just use </p>
<pre><code>c.send(strings.Replace(line, "PING", "PONG", 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'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're doing your own IRC parsing/message composition. That's fine, but there are a few great libraries that help with that. I'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'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'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'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
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传