3

Martini を使用して RESTful API を構築していますが、サービスに送信された book.json の内容にアクセスするのに苦労しています。

curl -X POST "http://localhost:8080/books" -H "Content-Type: application/json" -d @book.json

book.json はバイナリ ファイルではなく、JSON 配列を含む単純なテキスト ファイルです。送信された JSON にアクセスするにはどうすればよいですか? http.Request の PostForm が空です。

4

2 に答える 2

1

これが古いことは知っていますが、おそらくMartini Bindingを探しているでしょう

https://github.com/martini-contrib/binding

m.Post("/contact/submit", binding.Bind(ContactForm{}), func(contact ContactForm) string {
    return fmt.Sprintf("Name: %s\nEmail: %s\nMessage: %s",
        contact.Name, contact.Email, contact.Message)
})
于 2014-10-28T21:33:49.573 に答える
0

おそらく、デマーシャリングできる request.Body にデータがあります。この記事は問題をよく説明しています: http://nathanleclaire.com/blog/2013/11/30/fear-and-loathing-with-golang-and-angular-js/

于 2014-04-08T11:14:19.233 に答える