mattn on Nostr: Go の場合 f, err := os.Create("file") if err != nil { return err } defer f.Close() ...
Go の場合
f, err := os.Create("file")
if err != nil {
return err
}
defer f.Close()
というイディオムを覚えてしまうので、Close の書き忘れが無いんですよね。(Go の宣伝ではない)
あと Go の *os.File は GC で Close される。
Published at
2024-09-20 04:19:30Event JSON
{
"id": "07e52c6421f7b584f61d1879f9e923ae21a76a5f2e15f039dd5521622729b5ae",
"pubkey": "2c7cc62a697ea3a7826521f3fd34f0cb273693cbe5e9310f35449f43622a5cdc",
"created_at": 1726805970,
"kind": 1,
"tags": [],
"content": "Go の場合\n\nf, err := os.Create(\"file\")\nif err != nil {\n return err\n}\ndefer f.Close()\n\nというイディオムを覚えてしまうので、Close の書き忘れが無いんですよね。(Go の宣伝ではない)\n\nあと Go の *os.File は GC で Close される。",
"sig": "e311a5d74c360cc5dc66b6d9cbb5553a7e7535497a469c253cb8c6a1262db66f5fdce86ae1f1dd36a8f62f415da27999e95f12acc9eee98810f480f119450bd3"
}