Skip to content

Commit 3cb2299

Browse files
committed
chore: add backend guidelines
Signed-off-by: Gabriel Bernal <gbernal@redhat.com>
1 parent 8f170cb commit 3cb2299

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

CONTRIBUTING.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Thank you for your interest in contributing to the OpenShift Monitoring Plugin!
1414
- [React Component Patterns](#react-component-patterns)
1515
- [State Management](#state-management)
1616
- [TypeScript Best Practices](#typescript-best-practices)
17+
- [Go Backend Guidelines](#go-backend-guidelines)
1718
- [Testing Requirements](#testing-requirements)
1819
- [Internationalization (i18n)](#internationalization-i18n)
1920
- [Troubleshooting](#troubleshooting)
@@ -419,6 +420,46 @@ type PartialMetric = Partial<Metric>;
419420
type RequiredFields = Required<Pick<Config, "name" | "url">>;
420421
```
421422

423+
### Go Backend Guidelines
424+
425+
The backend that serves plugin assets and proxies APIs is written in Go (see `/cmd` and `/pkg`).
426+
Follow these Go-specific conventions in addition to the general naming rules:
427+
428+
#### Files and Packages
429+
430+
- **File names**: lowercase with underscores only when required (e.g., `plugin_handler.go`, `server_test.go`).
431+
- **Packages**: short, all lowercase, no underscores or mixedCaps (e.g., `proxy`, `handlers`).
432+
- **Tests**: co-locate `_test.go` files next to the implementation and keep table-driven tests when feasible.
433+
434+
#### Variables and Constants
435+
436+
- **Exported identifiers** use `MixedCaps` starting with an uppercase letter (`PluginServer`, `DefaultTimeout`).
437+
- **Unexported identifiers** use `mixedCaps` starting lowercase (`proxyClient`, `requestCtx`).
438+
- Favor descriptive names over abbreviations; keep short-lived loop variables concise (`i`, `tc`).
439+
- Group related constants using `const (...)` blocks.
440+
441+
#### Functions and Methods
442+
443+
- Exported functions and methods must have doc comments beginning with the function name.
444+
- Function names follow `MixedCaps` (`StartServer`, `newProxyHandler`).
445+
- Keep parameter order consistent (ctx first, dependencies before data structs) and return `(value, error)` pairs.
446+
- Ensure all files pass `go fmt ./cmd ./pkg` and `go vet ./...` before submitting.
447+
448+
#### Structs and Interfaces
449+
450+
- Struct names are `MixedCaps` (e.g., `ProxyConfig`, `TLSBundle`).
451+
- Exported struct fields must be capitalized if used by other packages or JSON marshaling. Always add JSON tags for serialized types:
452+
453+
```go
454+
type ProxyConfig struct {
455+
TargetURL string `json:"targetURL"`
456+
Timeout time.Duration `json:"timeout"`
457+
}
458+
```
459+
460+
- Interfaces describe behavior (`MetricsFetcher`, `ClientProvider`) and live near their consumers.
461+
- Keep files focused: one primary struct or related set of functions per file to ease reviews.
462+
422463
---
423464

424465
## Testing Requirements

0 commit comments

Comments
 (0)