Commit c07c44

2026-01-16 09:45:03 Melisha Dsouza: GoLang
CMMI/Guidelines/Coding Standard/Golang.md ..
@@ 18,7 18,7 @@
### **2. Project Layout & Structure**
We adhere to the community-standard **Go Project Layout**.
- ```
+ ```Golang
| Directory | Purpose |
| /cmd | Main applications. Directory names match the binary (e.g., cmd/api-server). |
| /internal | Private application and library code. Compiler-enforced privacy. |
@@ 41,7 41,7 @@
2. Third-party packages
3. Internal/Company packages
- ```
+ ```Golang
import (
"fmt"
"os"
@@ 77,7 77,7 @@
Avoid global state. Dependencies should be injected explicitly, typically via the constructor.
**Bad (Global State):**
- ```
+ ```Golang
func CreateUser() {
db.Execute(...) // "db" is a global variable
}
@@ 105,7 105,7 @@
#### **6.1 Inspectable Errors**
- Never use panic for standard error flow.
- Use %w to wrap errors to add context while preserving type.
- ```
+ ```Golang
if err := db.Query(); err != nil {
return fmt.Errorf("querying user failed: %w", err)
}
@@ 118,7 118,7 @@
#### **6.3 Indentation (Line of Sight)**
Handle errors early and return. Avoid else blocks after error checks.
- ```
+ ```Golang
// Bad
if err == nil {
// heavy logic
@@ 157,7 157,7 @@
- **Note**: Passing by value is often faster due to stack allocation logic.
#### **8.2 Slice Allocation**
If the length is known, pre-allocate slices to avoid resizing overhead.
- ```
+ ```Golang
// Good
users := make([]User, 0, len(ids))
```
@@ 165,7 165,7 @@
### **9. Testing**
#### **9.1 Table-Driven Tests**
Use table-driven tests for all logic-heavy functions.
- ```
+ ```Golang
func TestAdd(t *testing.T) {
tests := []struct {
name string
@@ 216,3 216,5 @@
- noctx # finds sending http request without context.Context
- revive # fast, configurable, extensible, flexible, and beautiful linter
```
+
+ **Document** - [Go Lang](https://docs.google.com/document/d/1EaOaSk-hbuje0igvIxl1DXcHQROc3KP-S49eD1IUGqg/edit?usp=sharing)
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9