Naming convention
Basically the field names follows a simple convention:
Entity
At entity level the field...:
- Is not exportable and must be lower case.
- The entity must provide a getter and setter following:
- Getter: must be the same as field name but exportable, so the capitalized field name.
- Setter: must start with the keyword
Set
followed by the capitalized field name (camel case).
For instance:
Advanced getter and Setter
Getter and Setter methods can follow your own naming rule. This is not recommended but you can do it. Please read the next section Entity Getter and Setter
Data Transfer Object - DTO
The DTOs are different to the Entity because the field sometimes must be exported, for instance, to JSON serialize.
In this case the DTO field names must follow this conventions:
- The field is exported, so starts with capital letter.
- In order to avoid overlapping with getter method, the field name must ends with a underscore
_
- If the DTO is mapped as JSON, the json tag must be added.
For instance:
Data Mapper Object - DMO
This kind of object is pretty similar to DTO and follows the same convention.
For instance:
MongoDB DMO
SQL DMO
Query Result Object - QRO
QRO is similar to DTO and follows the same convention. This one only exports to JSON the query results, so no getters and setters are needed
For instance:
Setting custom names at DTO, DMO and QRO
Torpedo supports custom field names in DTOs, DMOs and QROs objects. Each custom field name MUST be mapped to the respective entity field.
Mapping custom DTO field
The custom DTO's field can be mapped with its respective entity field via Go tag. The entity
is the core data model and all other objects turns around this one.
Torpedo support the tag torpedo.dto
in order to map this field and follow the pattern:
where:
<adapter>
is the input adapter. For instancehttp
<fieldName>
is the custom DTO field name to map.
For instance:
defining a DTO:
The entity looks like:
Mapping custom DMO field
DMO field mapping is pretty similar to DTOs mapping, but the tag name is different.
Torpedo supports the tag torpedo.dmo
in order to map this field and follow the pattern:
where:
<adapter>
is the output adapter. For instancememory
<fieldName>
is the custom DMO field name to map.
For instance:
defining the sql and mongoDB DMO:
The entity looks like:
Mapping custom QRO field
Finally, QRO objects follows the same behaviour that previous ones.
Torpedo supports the tag torpedo.qro
in order to map the field following the pattern:
where:
<adapter>
is the output adapter. For instancememory
<fieldName>
is the custom DMO field name to map.
For instance:
defining QRO:
The entity looks like: