Feedback on my twitch irc library

polaris · 2017-07-20 08:30:11 · 588 次点击    
这是一个分享于 2017-07-20 08:30:11 的资源,其中的信息可能已经有所发展或是发生改变。

Hey,

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.

I wrote this library a few months ago and was wondering if I could get some feedback on it.

You could use this library to e.g. write a twitch bot.

https://github.com/gempir/go-twitch-irc

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.


评论:

ShawnSmith08:

Your code looks pretty good, but it looks like you're only allowing for one callback function per OnMessage.

You could turn that into an slice of functions and iterate over the slice to call each function.

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.

gempir:

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.

allhatenocattle:

Overall pretty good. A couple of minor nits:

https://github.com/gempir/go-twitch-irc/blob/master/client.go#L14 naming is typically camelCase and this doesn't need to be exported so switch to ircTwitch

https://github.com/gempir/go-twitch-irc/blob/master/client.go#L73 printing conn when there was an error calling dial(), it is almost certainly going to be empty

https://github.com/gempir/go-twitch-irc/blob/master/client.go#L96 If len(messages) is zero, the range statement on L99 won't do anything so this check isn't needed

https://github.com/gempir/go-twitch-irc/blob/master/client.go#L109-L110 why use fmt.Sprintf inside a fmt.Fprintf, can do it all with the beginning fmt.Fprintf

https://github.com/gempir/go-twitch-irc/blob/master/client.go#L126 fmt.Sprintf() isn't needed, just use

c.send(strings.Replace(line, "PING", "PONG", 1))

https://github.com/gempir/go-twitch-irc/blob/master/client.go#L155 break isn't needed since not in a loop

https://github.com/gempir/go-twitch-irc/blob/master/client.go#L169 declare func(channel string, user User, message Message) as a type like callback and then the On*Message func definitions will look cleaner

Cheers! edit - some additional notes

shazow:

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 https://github.com/sorcix/irc, might save you some trouble with unexpected bugs.

SpokenSpruce:

Neither master nor the v2 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.

gempir:

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

So I just went with my online parser

shazow:

That's cool, good work! :)

yamamushi:

Glad you posted this! It will likely come in handy when I rewrite TwitchInstallsArchLinux in Golang and try to boot it up again.

gempir:

Oh you wrote that? Awesome, the idea was funny as hell

yamamushi:

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).

I look forward to using your library :)


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

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