

Gotweet - command-line Twitter client in Go - dchest
http://codingrobots.org/p/gotweet/doc/tip/www/index.wiki

======
dchest
Twitter clients are the new "Hello world" of programming. I wrote it to try
out and get familiar with the language.

While writing it I found a bug in JSON library
(<http://code.google.com/p/go/issues/detail?id=73>), which has been fixed
quickly by Go developers (in less than an hour).

Currently their http library doesn't support basic authentication, and their
http.send method, which allows tweaking headers, is private, so I had to copy
and paste three methods from http package and add authentication (see
http_auth.go).

The hardest part for me was to get those io things right (I was confused by
[]byte vs bytes package, and io.Writers/Readers).

I love cross-compilation: both binaries (for Mac OS X and Linux) were compiled
on Mac.

~~~
uriel
> I love cross-compilation: both binaries (for Mac OS X and Linux) were
> compiled on Mac.

Indeed, the Plan 9/ken way of structuring compilers rocks. All compilation is
cross-compilation! Simple, elegant, reliable.

------
jrockway
I continue to not be particularly excited by Go. My first thought when reading
this code was "wow, that's a lot of verbosity mixed with a lot of line noise".
If this was Some Random Guy's project, nobody would have heard of it and
nobody would care. But since Google is paying for it, it's suddenly amazing?
No exceptions? Seriously?

If you want a better system programming language than C, why not use Haskell?
If it is better than Go in perhaps every measurable way. And there is already
an HTTP library that supports basic auth...

~~~
dchest
Just a note: don't rely on my code to get a taste of language, because,
obviously, it was "hacked together while learning a language" instead of
"programmed". There are sources for packages on Go website
<http://golang.org/pkg/> that are written clearly.

~~~
jrockway
I think all the problems with your code are Go problems, not problems with how
you used it. Things like Twitter clients always look ugly in low-level
languages, however.

------
gcampbell
I note a comment in your code that "Twitter sends malformed JSON, with top-
level array. Workaround: put it under 'tweets'." As I understand it, a top-
level array is perfectly legal JSON (see <http://www.ietf.org/rfc/rfc4627> \-
"A JSON text is a serialized object or array."). Are there other problems with
Twitter's JSON, or does Go's JSON implementation fail to support top-level
arrays?

~~~
dchest
Ah. Someone at #go-nuts said it wasn't valid, so I made the change and it
worked. If it's valid, than yes, it must be a bug in Go's json package. Edited
the comment, filed a bug report
(<http://code.google.com/p/go/issues/detail?id=114>). Thanks!

~~~
gcampbell
As a note, top-level JSON arrays have been demonstrated to have some security
problems in web browsers when delivered via GET requests; see
<http://haacked.com/archive/2009/06/25/json-hijacking.aspx> for more. (This
isn't relevant for JSON-as-interchange-format in other contexts, of course).

------
pieter
I wanted to check out the source of the program, but getting to the source on
that site is just too much trouble.

~~~
dchest
I've added a link to zip archive to the home page.

