0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

golangのお勉強3

0
Last updated at Posted at 2017-05-06

概要

swaggerで作ったコードを読んだり実行したりして下準備。


ローカルのimport(非推奨)でswagger生成のクライアントを使いたい。。どうするのか。

importの仕方を調べる

【Go】import 書き方まとめ - Qiita
http://qiita.com/taji-taji/items/5a4f17bcf5b819954cc1

Goでpackageのimportのやり方(自分用に整理) - Qiita
http://qiita.com/shiwork/items/a213b1af2da7f7f8ea22

ビルドもできないし考え方が違うのね
でもとりあえずローカルインポートで動かしたい

goのimportを自動的に追加/削除してくれる「goimports」を試してみた - Misc Notes
http://y0m0r.hateblo.jp/entry/20140112/1389501259

自動でインポート


チュートリアル読めばいいけど、、

チートシートをメモ

golang チートシート - Qiita
http://qiita.com/jca02266/items/56a4fb7b07b692a6bf34

バッドノウハウ系

魅力もあるが注意も実は多そう。。
クラスがかけないという話を聞いたけど、まだ実感として理解するにいたってない。

Goのアンチパターン - GolangRdyJp
http://golang.rdy.jp/2016/07/26/antiptn/

Go言語(Golang) はまりどころと解決策
http://www.yunabe.jp/docs/golang_pitfall.html


jsonと構造体

Unmarshalってなに?

Goのjson.Marshal/Unmarshalの仕様を整理してみる · I Will Survive
http://blog.restartr.com/2014/08/13/golang-json-marshal-unmarshal/


関数をとりあえず使う

複数の戻り値の受け方を調べる

golangの関数をまとめてみた。 - Qiita
http://qiita.com/Jumpei_Chikamo/items/dd8acfba3dfe32530717

複数の戻り値を簡単に指定できる


swagger-codegenの古いバージョンだとclientのコードが変だった

エラーの受け取り方について

省略形式での変数再宣言が許される場合 - Qiita
http://qiita.com/Jxck_/items/2616abafea89ee97c477

すでに err のような取回す変数が宣言されていて、それ以外の値も含めた多値を返す関数を呼ぶとき。


swagger-codegenの古いバージョンだとclientのコードが変だった

swaggerをdockerでインストールし直す

swagger-api/swagger-codegen: swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
https://github.com/swagger-api/swagger-codegen


swagger-codegenでのコードで使われていたパッケージ

swagger-codegenのgo-clientのコード

よくわからないけど、restfulに近づけたってことかしら。

  • 以前のバージョンで使われていたパッケージ

github.com/dghubble/sling

Sling is a Go HTTP client library for creating and sending API requests.

  • 現行のバージョンで使われていたパッケージ

github.com/go-resty/resty

Simple HTTP and REST client for Go inspired by Ruby rest-client. Features section describes in detail about resty capabilities.


swagger-codegenでのコードの実行の仕方が説明されていないので調べつつ実行した

swagger-codegenでのコードの実行の仕方が説明されていないので調べつつ実行した

main.goを作って実行。
接続先は...WithBasePath()で上書きできる。
(AWSにしていたので、ローカルで同じくcodegenしたサーバーにすげ替える。prodなどに注意。)

package main

import (
	"./go-client"
	"fmt"
)

func main() {
	//UserApi
	UserApi := swagger.NewUserApiWithBasePath("http://localhost:8080/prod")
	user_pre, user_res, user_err := UserApi.PostUser("title", "contents")
	//print(user_pre, user_res, user_err)
	fmt.Printf("%s\n", UserApi.Configuration)
	fmt.Printf("%s\n", user_pre)
	fmt.Printf("%s\n", user_res)
	fmt.Printf("%s\n", user_err)
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?