Recently I looked up Google’s newish language, go, at wiki, and felt it might be nearly perfect for a project I had in mind that perl might not really be the best tool for. I know, perl does every damn thing. But some of the interesting and exciting features of go – a compiled language – include garbage collection, concurrency (read: fairly trivial multi-threading), built-in UTF-8, and an apparently new approach to object-orientation; this appears to truly be a modern language. It should also be noted that go is the spawn of Ken Thompson, of Unix fame (and, supposedly, this quote), and Rob Pike, of Plan 9 fame, and also, er, some guy neither I nor wiki have heard of before, Robert Griesemer, I’m sure his credentials must be equally impressive.
So anyway, I started reading golang.org and learning go, but learning from specifications and stuff sucks, so I picked up a copy of Programming in Go. But I also learn from doing my own stuff, so I of course needed to do some things not already in go that really should be done in pkgs – what the rest of the compiled-language world calls libraries, and what the scripting-language world calls modules – so I started hacking up some pkgs to do these things.
All three are now at what I consider a decent state, so I’ve uploaded them to my go-pkgs repo on github. Here’s a breakdown of each:
My find pkg is something like a go implementation of the find Unix command, or the find perl function. It can do much more than just find by feeding it an appropriate function – like the perl implementation. Currently it has helpers to find anything whose name matches a given regex and to find any directory whose name matches a given regex. There will be additional helpers in the future. Eventually this pkg will probably do concurrency, once I get to that chapter in Programming in Go (my understanding of how to do it exists but is pretty loose at present).
My slog pkg utilizes the cgo mechanism to provide the ability to log to syslog with the facility specified, which is oddly missing from go’s log/syslog pkg. This pkg does *not* support syslog options at present, simply because I haven’t implemented them yet. Eventually this pkg will probably be object-oriented… once I get to that chapter in Programming in Go. See above.
Warning: Rant. This was spawned from my only real criticism of go thus far: its time pkg, and specifically, the time.Time.Format method. Where it mentions UnixDate? Referring to a format you can get back, not a format you can use; somehow I thought it meant the traditional Unix date/time format specifiers we all know and, er, love from “man 3 strftime”. Instead, go uses a bizarro-world format where you actually type the date like you want it back – EXCEPT you can only use certain things to indicate certain things – like the strftime format, only different, so you have to learn an entirely new format. For example, 03 means the hour in 12-hour format and 01 means the month in numerical format. And where can you find this crap documented? In the source. My date pkg implements a wrapper around time.Time.Format for formats I’ll use fairly often. I may add to it as time goes by, ie if I need to use a different format that’s not provided by the time pkg already.
It should be noted that I did not look for existing third-party pkgs for these things at all. For one, I just don’t care about anyone else’s implementations, and for two, it’s much more useful to me to figure out how to implement them myself, and how to improve them over time. So these are pretty definitely not the best ways to do these things, and the APIs will change. While is fine, since I’m doing these things form myself, above and beyond all other considerations. But it will be nice if someone else finds them useful.