2012/03/29


ようやくリリースされました!
go1 released

We've just tagged a new Go release: go1.
Go 1 is a major release of Go that will be stable in the long term.
It is intended that programs written for Go 1 will continue to compile
and run correctly, unchanged, under future versions of Go 1.

The Go 1 release notes list the significant changes since the last
release and explain how to update your code:
        http://golang.org/doc/go1.html

To learn about the future of Go 1, read the Go 1 compatibility document:
        http://golang.org/doc/go1compat.html

Go 1 is available as binary distributions for the
FreeBSD, Linux, Mac OS X, and Windows operating systems.
To install a binary distribution, follow these instructions:
        http://golang.org/doc/install

If you prefer to build from source, follow these instructions:
        http://golang.org/doc/install/source

The Go team would like to thank all our contributors from the open
source community. We could not have done it without their help.
See the full list of contributors here: http://golang.org/CONTRIBUTORS

We also thank our users. We hope you enjoy Go 1.

Have fun. (And tell your friends! ;-)

Andrew

https://groups.google.com/forum/?fromgroups#!topic/golang-nuts/fVonEtwNSFc
初めてgo言語を触った時、C++よりも型が柔らかく、ネイティブコードへのコンパイル型言語なのにダックタイピングやgcを備える非常に柔軟な言語に感動を覚えました。いろんな可能性を秘めているし、C++よりも簡単なコードで立派なアプリケーションが書ける。そう思いました。(もちろんC++も大好きです)
リリースまでに送ったパッチは56個でした。主にWindowsのAPI周り、HTTPプロキシ処理の初期実装やソケットサーバのバグ修正、特に他のOSで先に実装された機能のWindows版の実装などをお手伝い出来ました。
golang-devチームにとっても僕にとってもgo1 releaseは一つの区切りでしか無いでしょう。今後もまた、パッチを送りつづけるでしょう。

質の高い言語をこんなにも短期でリリースしてしまったgolang-devチームに拍手を送りたいと思います。
Posted at by



2012/03/23


そう言えば、go言語版を書いてなかったなーと思ったのでエントリ。
いかにしておっぱい画像をダウンロードするか?2012 - ゆーすけべー日記

4年以上前のBlog記事で非常に評判がよく「高校生がプログラミングをはじめるキッカケになった」というエントリーがあります。 題名は「 いかにして効率よく大量のおっぱい画像をダウンロードするか 」。 僕...

http://yusukebe.com/archives/20120229/072808.html
こういう並行処理を簡単に書けてネイティブ実行出来るgo言語はやっぱり素晴らしいなぁと思いました。
# oppai [appid] [outdir] [keyword]
といった感じにお使い下さい。 package main

import (
    "crypto/md5"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
    "net/url"
    "os"
    "path/filepath"
    "strconv"
    "strings"
)

type response struct {
    SearchResponse struct {
        Image struct {
            Results []struct {
                MediaUrl    string
                ContentType string
            }
        }
    }
}

func main() {
    if len(os.Args) != 4 {
        println("usage: oppai [appid] [outdir] [keyword]")
        os.Exit(1)
    }
    appid, outdir, keyword := os.Args[1], os.Args[2], os.Args[3]

    total := 0
    offset := 0
    outdir, _ = filepath.Abs(outdir)
    param := url.Values{
        "AppId":       {appid},
        "Version":     {"2.2"},
        "Market":      {"ja-JP"},
        "Sources":     {"Image"},
        "Image.Count": {strconv.Itoa(50)},
        "Adult":       {"off"},
        "Query":       {keyword},
    }
    quit := make(chan bool)

    md5hash := md5.New()
    to_filename := func(s, t stringstring {
        md5hash.Reset()
        md5hash.Write([]byte(s))
        token := strings.SplitN(t, "/"2)
        if strings.Index(token[1], "jpeg") != -1 {
            token[1] = "jpg"
        }
        return fmt.Sprintf("%X.%s", md5hash.Sum(nil), token[1])
    }

    for {
        param["Image.Offset"] = []string{strconv.Itoa(offset)}
        res, err := http.Get("http://api.bing.net/json.aspx?" +
            param.Encode())
        count := 0
        if err == nil {
            var result *response
            err = json.NewDecoder(res.Body).Decode(&result)
            res.Body.Close()
            if err != nil {
                println(err.Error())
                break
            }
            if count = len(result.SearchResponse.Image.Results); count ==
                0 {
                total = -1
                break
            }
            for _, r := range result.SearchResponse.Image.Results {
                go func(url, ct string) {
                    filename := filepath.Join(outdir, to_filename(url, ct))
                    if f, derr := os.Create(filename); derr == nil {
                        defer f.Close()
                        dres, derr := http.Get(url)
                        if derr == nil && dres.ContentLength > 0 &&
                            strings.Index(dres.Header.Get("Content-Type"), "image/") == 0 {
                            _, derr = io.CopyN(f, dres.Body, dres.ContentLength)
                            if derr != nil {
                                println(derr.Error())
                            } else {
                                println(filename)
                            }
                        }
                    }
                    quit <- false
                }(r.MediaUrl, r.ContentType)
            }
        } else {
            total = -1
            break
        }
        offset += count
        total += count
    }

    for total > 0 {
        <-quit
        total--
        println(total)
    }
}
けしからんけしからん。
追記1
終了を待ってなかった。 ...orz

追記2
ちょっとエラー処理足した。

Go言語プログラミング入門on Google App Engine Go言語プログラミング入門on Google App Engine
横山 隆司
秀和システム 単行本 / ¥151 (2011年12月14日)
 
発送可能時間:

はじめての「Go言語」: Googleが提供する高速コンパイラ言語 (I/O BOOKS) はじめての「Go言語」: Googleが提供する高速コンパイラ言語 (I/O BOOKS)
茨木 隆彰
工学社 単行本 / ¥2,090 (2010年11月01日)
 
発送可能時間:

Posted at by



2012/03/09


VDBIは一日にして出来上がりその日中にXMLRPCプロトコルからJSONRPCプロトコルに変わってしまったという酷いプロジェクトなんだけど、JSONRPCサーバは色んな言語から扱えるのでやってて楽しい。
mattn/vdbi-vim - GitHub

Database client for Vim

https://github.com/mattn/vdbi-vim
最近clojureに興味はあるんだけど、一向にclojure力があがらないので、勉強がてらVDBIのサーバとおしゃべりしてみた。
使ったのは clj-rpc というJSONRPCライブラリ。
zhuangxm/clj-rpc - GitHub

a simple web rpc using clojure and json protocol

https://github.com/zhuangxm/clj-rpc
最初、エンドポイント指定時に :on-witejson に指定しないとデフォルトで clj プロトコル(通信データがJSONじゃなくclojureのコード)になるという罠にどっぷりハマってしまったけど、なんとか動いた。
(ns vdbi-demo
  (:require [clj-rpc.client :as client]))
(def endp (client/rpc-endpoint :server "localhost" :port 9876 :on-wire "json"))
(client/invoke-rpc endp "connect" ["dbi:SQLite:dbname=c:/temp/foo.db" "" ""])
(client/invoke-rpc endp "prepare" ["select * from foo"])
(client/invoke-rpc endp "execute" [])
(let [rows (client/invoke-rpc endp "fetch" [-1])]
  (reduce (fn [rows row]
    (reduce (fn [cols col]
      (print (str col ","))){}, row)
    (println)){}, rows))
1,あいう,
2,かきく,
3,psgix.harakiri,
ちなみにこの clj-rpc は :on-wire をURLのおケツに引っ付けてしまうので、物によっては動かないサーバもあるかも。
あと vimclojure をいれて let vimclojure#FuzzyIndent=1
let vimclojure#HighlightBuiltins=1
let vimclojure#HighlightContrib=1
let vimclojure#DynamicHighlighting=1
let vimclojure#ParenRainbow=1
という設定をvimrcに書いておくとコードが七色になるのでいれるべし。
vimclojure
Posted at by