4. Add Endpoint
Due to the fact that our application must work locally and on AWS, the endpoints must be defined in multiple files for the corresponding frameworks.
In addition, the endpoint must be defined for the Swagger documentation.
Changes must therefore be made in at least 3 places. As this is very error-prone and also leads to code duplication, we counteract this problem by automatically generating the source code for the endpoints.
To provide the necessary information, we use the comments that are also used to create the Swagger documentation.
Endpoint Extractor
The endpointextractor (see /tools/endpointextractor) is used to extract the necessary information about the endpoint (rest method, path and name of the function) from our source code.
Extraction is not just a simple search, the source code is also parsed.
Code Generation
The code generation takes place with the help of codegen (see /tools/codegen’). This generates the necessary code for AWS and Gin for us.
The generated code is stored under /cmd/gin and /cmd/lambda and is not checked into version management as it is generated automatically.
The code generation can be done manually via the VsCode tasks “Gen: Generate Entry Points (Gin)” and “Gen: Generate Entry Points (Lambda)”