2013/11/15

Recent entries from same category

  1. Go 言語プログラミングエッセンスという本を書きました。
  2. errors.Join が入った。
  3. unsafe.StringData、unsafe.String、unsafe.SliceData が入った。
  4. Re: Go言語で画像ファイルか確認してみる
  5. net/url に JoinPath が入った。

Treasure Data の REST API をコールするライブラリを書いた。
REST API | Treasure Data

REST API The user can control Treasure Data using the public REST API. This article will explain how...

http://docs.treasure-data.com/articles/rest-api
mattn/go-treasuredata ・ GitHub
https://github.com/mattn/go-treasuredata
使い方はこんな感じ。
client := treasuredata.NewClient("TREASUREDATA-API-KEY")
job, _ := client.JobIssueHive("mydb""select * from mytable")
client.JobResultFunc(job.JobId, func(row []interface{}) error {
    fmt.Println(row)
    return nil
})
結果は JSON で貰えます。データが大量に返る場合があるのでデータ取得はコールバックで行います。error を返せば途中で抜けられます。
td フォルダにはコマンドラインツールが入っていて、クエリをコマンドラインから投げられます。
$ cd td
$ go build td.go
$ export TREASURE_DATA_API_KEY=xxxxxx
$ ./td -d mattn -q 'select * from unko'
["残念","小",{"size":"小","feel":"残念","time":"1363948092"},1363948092]
["残念","小",{"size":"小","feel":"残念","time":"1363948093"},1363948093]
["残念","小",{"size":"小","feel":"残念","time":"1363948094"},1363948094]
["残念","小",{"size":"小","feel":"残念","time":"1363948095"},1363948095]
["残念","小",{"size":"小","feel":"残念","time":"1363948096"},1363948096]
["残念","小",{"size":"小","feel":"残念","time":"1363948097"},1363948097]
["爽快","大",{"size":"大","feel":"爽快","time":"1363948098"},1363948098]
["残念","小",{"size":"小","feel":"残念","time":"1363948091"},1363948091]
["残念","小",{"size":"小","feel":"残念","time":"1363948092"},1363948092]
["残念","小",{"size":"小","feel":"残念","time":"1363948093"},1363948093]
["残念","小",{"size":"小","feel":"残念","time":"1363948094"},1363948094]
["残念","小",{"size":"小","feel":"残念","time":"1363948095"},1363948095]
["残念","小",{"size":"小","feel":"残念","time":"1363948096"},1363948096]
["残念","小",{"size":"小","feel":"残念","time":"1363948097"},1363948097]
["爽快","大",{"size":"大","feel":"爽快","time":"1363948098"},1363948098]
["残念","小",{"size":"小","feel":"残念","time":"1363948092"},1363948092]
["残念","小",{"size":"小","feel":"残念","time":"1363948093"},1363948093]
["残念","小",{"size":"小","feel":"残念","time":"1363948094"},1363948094]
["残念","小",{"size":"小","feel":"残念","time":"1363948095"},1363948095]
["残念","小",{"size":"小","feel":"残念","time":"1363948096"},1363948096]
["残念","小",{"size":"小","feel":"残念","time":"1363948097"},1363948097]
["爽快","大",{"size":"大","feel":"爽快","time":"1363948098"},1363948098]
["残念","小",{"size":"小","feel":"残念","time":"1363948091"},1363948091]
["残念","小",{"size":"小","feel":"残念","time":"1363948092"},1363948092]
["残念","小",{"size":"小","feel":"残念","time":"1363948093"},1363948093]
["残念","小",{"size":"小","feel":"残念","time":"1363948094"},1363948094]
["残念","小",{"size":"小","feel":"残念","time":"1363948095"},1363948095]
["残念","小",{"size":"小","feel":"残念","time":"1363948096"},1363948096]
["残念","小",{"size":"小","feel":"残念","time":"1363948097"},1363948097]
["爽快","大",{"size":"大","feel":"爽快","time":"1363948098"},1363948098]
毎日のウンコのサイズを treasure data に入れておいて、go-treasuredata で履歴を照会出来る様にしておけば健康管理もバッチリですね。
Posted at by | Edit