mobile hack 楽しい生活情報を携帯しよう

コンセプト「楽しい生活情報を携帯する」


Golang Go言語で install をすっ飛ばして MessagePack を使いたい

MessagePack の形式でただ単に、出力(encode)したいだけなので下記でも良いって思っていたんですが、github.com

今後 RPC をやっぱり使いたいってなった場合、面倒な事になりそうなので、
公式にも書いて有る github.com の codec を使おうと思いますが、使い方が今は良く分から無いです。


下記を参考に使って行こうと思います。qiita.com

Golang Go 言語の Maritini で JSON (の値) を POST 送信して JSON を返却する

import したいので、下記を実行。

$ go get github.com/codegangsta/martini
$ go get github.com/martini-contrib/binding
$ go get github.com/martini-contrib/render

post_server.go を下記にする。

package main

import (
    "net/http"

    "github.com/codegangsta/martini"
    "github.com/martini-contrib/binding"
    "github.com/martini-contrib/render"
)

type Post struct {
    Key string `json:"key" binding:"required"`
    Value string `json:"value"`
}

func (p Post) Validate(errors *binding.Errors, req *http.Request) {
    if len(p.Key) < 1 {
        errors.Add([]string{}, "PostError", "Too short; minimum 1 characters")
    } else if 120 < len(p.Key) {
        errors.Add([]string{}, "PostError", "Too long; maximum 120 characters")
    }
}

func main() {
    m := martini.Classic()
    m.Use(render.Renderer())

    m.Post("/api", binding.Json(Post{}), binding.ErrorHandler, func(post Post, r render.Render) {
        r.JSON(200, map[string]interface{}{"hello": "world"})
    })

    m.Run()
}
$ go run post_server.go
[martini] listening on :3000 (development)

別の端末から下記を実行。

$ curl -d '{"key":"1","value":""}' http://localhost:3000/api

content は下記が返却されます。

{"hello":"world"}

色々、拙い実装だとは思いますが、私が良く分から無い所が多い Golang 何で、兎に角、世(blog)に出します。

Nginx で私も同じ現象が起きたてたので助かりました。phpがエラーログを全然出してくれなくてハマった件

altarf.net

Nginx 側の設定かと思ったら、
PHP-FPM の設定の catch_workers_output を変更する必要がありました。

catch_workers_output = yes

これ便利なのかな。Visual Studio OnlineがGitHubやJenkins、Xcode Buildなど外部のリポジトリやビルドシステムをサポート。プライベートリポジトリは無料で制限なく作成可能 - Publickey

www.publickey1.jp