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:
gempir: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.
allhatenocattle: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.
shazow: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
SpokenSpruce: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.
gempir:Neither
master
nor thev2
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.
shazow: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
yamamushi:That's cool, good work! :)
gempir:Glad you posted this! It will likely come in handy when I rewrite TwitchInstallsArchLinux in Golang and try to boot it up again.
yamamushi:Oh you wrote that? Awesome, the idea was funny as hell
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 :)
