Conversation
vvakame
added a commit
to vvakame/go-harlog
that referenced
this pull request
Oct 1, 2019
Owner
Author
|
とりあえず適当にGCSにアクセスしてHARファイルを作ってみる。 ctx := context.Background()
hc, err := google.DefaultClient(ctx, storage.ScopeReadWrite)
if err != nil {
panic(err)
}
// inject HAR logger!
har := &harlog.Transport{
Transport: hc.Transport,
}
hc.Transport = har
client, err := storage.NewClient(
ctx,
option.WithHTTPClient(hc),
)
if err != nil {
panic(err)
}
bucket := client.Bucket(*bucket)
{
object := bucket.Object("2019-10-01-harlog/hello.txt")
r, err := object.NewReader(ctx)
if err != nil {
panic(err)
}
b, err := ioutil.ReadAll(r)
if err != nil {
panic(err)
}
fmt.Println(string(b))
}
{
object := bucket.Object("2019-10-01-harlog/goodnight.txt")
w := object.NewWriter(ctx)
_, err = w.Write([]byte("Good night, world!"))
if err != nil {
panic(err)
}
err = w.Close()
if err != nil {
panic(err)
}
}
// dump HAR file!
b, err := json.MarshalIndent(har.HAR(), "", " ")
if err != nil {
panic(err)
}
err = ioutil.WriteFile("gcs.har", b, 0644)
if err != nil {
panic(err)
}ChromeのDevToolsとかで見れる。 |
Owner
Author
Owner
Author
Owner
Author
|
gRPCでも同様のことができるといいなーと思うけど、streamとかあるしHAR形式では難しいかな…。 |
This was referenced Oct 3, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.







sinmetalと話をして、GCSとかCloud Pub/Subは裏がREST APIなので、Transportで頑張ればプロダクションコードに手を加えずにモック実装にできるのでは?という会話があった。
そっちはそっちでやるといいと思うんだけど、裏側で行われている通信内容をとりあえずチェックしたくない?という気持ちになったのでやってみることにした。
HTTPリクエストの可視化というとまぁ HARファイルじゃない?ということで
net/httpのClientのTransport(RoundTripper)にログ取りの処理を突っ込んでみるべ、という発想で作られたのがこのライブラリ。https://github.com/vvakame/go-harlog