Go Comments
Go Comments (Golang)
In Go Comments are used to explain code, improve readability, and help in documentation.
Go supports two types of comments.
1️⃣ Single-line
Used for short explanations.
👉 Everything after // on the same line is ignored by the compiler.
2️⃣ Multi-line (Block)
Used for longer explanations or documentation blocks.
3️⃣ Inline
Used on the same line as code.
4️⃣ Commenting Out Code (Debugging)
Or:
5️⃣ Documentation Comments (Very Important in Go)
Go uses special comments to generate documentation using godoc.
Function
Package
⚠️ Rule:
Documentation comments must start with the name of the item (function, package, struct).
6️⃣ Best Practices
✔ Keep It simple and clear
✔ Explain why, not obvious what
✔ Avoid unnecessary use It.
Summary
| Comment Type | Syntax |
|---|---|
| Single-line | // |
| Multi-line | /* */ |
| Documentation | // Name ... |
