サンプルを元に。 Google Groupの投稿を元に、以下のスクリプトを書いた。 元にするスクリプトがあるため、著作権は元のスクリプトに準ずる。 package main import ( "bytes" "fmt" "log" "net/http" "text/template" ) type LineOfLog struct { RemoteAddr string ContentType string Path string Query string Method string Body string } var TemplateOfLog = ` Remote address: {{.RemoteAddr}} Content-Type: {{.ContentType}} HTTP method: {{.Method}} path: {{.Path}} query string: {
![【個人メモ】Golang HTTP リクエストの内容をログに出す - Qiita](https://cdn-ak-scissors.b.st-hatena.com/image/square/76dd46e173b5debe814ea0cb4735125c1ac04680/height=288;version=1;width=512/https%3A%2F%2Fqiita-user-contents.imgix.net%2Fhttps%253A%252F%252Fcdn.qiita.com%252Fassets%252Fpublic%252Farticle-ogp-background-9f5428127621718a910c8b63951390ad.png%3Fixlib%3Drb-4.0.0%26w%3D1200%26mark64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTkxNiZoPTMzNiZ0eHQ9JUUzJTgwJTkwJUU1JTgwJThCJUU0JUJBJUJBJUUzJTgzJUExJUUzJTgzJUEyJUUzJTgwJTkxR29sYW5nJTIwSFRUUCUyMCVFMyU4MyVBQSVFMyU4MiVBRiVFMyU4MiVBOCVFMyU4MiVCOSVFMyU4MyU4OCVFMyU4MSVBRSVFNSU4NiU4NSVFNSVBRSVCOSVFMyU4MiU5MiVFMyU4MyVBRCVFMyU4MiVCMCVFMyU4MSVBQiVFNSU4NyVCQSVFMyU4MSU5OSZ0eHQtY29sb3I9JTIzMjEyMTIxJnR4dC1mb250PUhpcmFnaW5vJTIwU2FucyUyMFc2JnR4dC1zaXplPTU2JnR4dC1jbGlwPWVsbGlwc2lzJnR4dC1hbGlnbj1sZWZ0JTJDdG9wJnM9MjgxZWI3OTg4ODc3YmE2NTA1NzI2N2M1YWRlM2E5ZWE%26mark-x%3D142%26mark-y%3D112%26blend64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTYxNiZ0eHQ9JTQwZnV0b2FzZSZ0eHQtY29sb3I9JTIzMjEyMTIxJnR4dC1mb250PUhpcmFnaW5vJTIwU2FucyUyMFc2JnR4dC1zaXplPTM2JnR4dC1hbGlnbj1sZWZ0JTJDdG9wJnM9YjY4ODc5Y2Q1ODI0Njk4NWQ3MjQ2NmQ0Y2MwMTM3YmU%26blend-x%3D142%26blend-y%3D491%26blend-mode%3Dnormal%26s%3Dd550074684d910374a34a48247ba96c7)