Skip to content

Commit e7c8655

Browse files
Danielius1922Daniel Adam
authored and
Daniel Adam
committed
Add DEVELOPER.md with basic code stylistic guide
1 parent 3ddbcb3 commit e7c8655

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

DEVELOPER.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Developer Guidelines
2+
3+
## Golang code
4+
5+
### Formatting
6+
7+
Format your code using `go fmt -s`. Formatting of pushed code is automatically checked by GitHub action.
8+
9+
### Style
10+
11+
General guideline is to follow the code conventions of the surrounding code to keep the style within files consistent.
12+
13+
The following rules are recommendations and are not required to be _always_ followed. Just use common sense to discern when to ignore a recommendation.
14+
15+
#### YAML tags
16+
17+
Services are configured using `.yaml` files, which are unmarshaled into a Golang structures on service start. Therefore there must be a strict correspondence between keys in `.yaml` files and YAML tags on the field of Golang configuration structure.
18+
19+
For field names and YAML tags `camelCase` is used. Abbreviations and acronyms are all upper-case; except for tags at the beginning of a word when they should be all lower-case. Tag name should start with a lower-case letter, but otherwise should copy the field name.
20+
21+
Example:
22+
23+
```Go
24+
type Example struct {
25+
Event string `yaml:"event"`
26+
EventURL string `yaml:"eventURL"`
27+
ExpiresIn time.Duration `yaml:"expiresIn"`
28+
ID string `yaml:"id"`
29+
}
30+
```
31+
32+
#### JSON tags
33+
34+
Marshaling to and unmarshaling from JSON is used by structures that are part of public API. Therefore there might be a specification that defines how the marshaled fields must be named in a payload (for example: `subscriptionId`, `eventsUrl` from [OCF Cloud API for Cloud Services Specification](https://openconnectivity.org/specs/OCF_Cloud_API_For_Cloud_Services_Specification_v2.2.4.pdf)).
35+
36+
For JSON tags strict `camelCase` is used, abbreviations and acronyms have the first letter upper-case and the rest is lower-case. Tag name should start with a lower-case letter and should usually copy the field name (this rule might be broken when a field is required to have a specific name).
37+
38+
Example:
39+
40+
```Go
41+
type Example struct {
42+
Event string `json:"event"`
43+
EventURL string `yaml:"eventUrl"`
44+
ExpiresIn time.Duration `yaml:"expiresIn"`
45+
ID string `yaml:"id"`
46+
}
47+
```

0 commit comments

Comments
 (0)