Signed-off-by: bblandSigned-off-by: bbland1 <104288486+bbland1@users.noreply.github.com> |
||
|---|---|---|
| .. | ||
| csharp | ||
| golang | ||
| java | ||
| nestjs | ||
| nodejs | ||
| python | ||
| react | ||
| README.md | ||
| func.go | ||
| generators.go | ||
| manager.go | ||
README.md
Generators
This directory contains the code generators for different programming languages. Each generator is responsible for generating code based on the OpenFeature flag manifest.
Structure
Each generator should be placed in its own directory under /internal/generators. The directory should be named after the target language (e.g., golang, react).
Each generator directory should contain the following files:
language.go: This file contains the implementation of the generator logic for the target language. Replacelanguagewith the name of the target language (e.g.,golang.go,react.go).language.tmpl: This file contains the template used by the generator to produce the output code. Replacelanguagewith the name of the target language (e.g.,golang.tmpl,react.tmpl).
How Generators Work
Each generator consists of two main components: the language.go file and the language.tmpl file. The language.go file contains the logic for processing the feature flag manifest and generating the output code, while the language.tmpl file defines the template used to produce the final code.
language.go
The language.go file is responsible for reading the feature flag manifest, processing the data, and applying it to the template defined in the language.tmpl file. This file typically includes functions for parsing the manifest, preparing the data for the template, and writing the generated code to the appropriate output files.
language.tmpl
The language.tmpl file is a text template that defines the structure of the generated code. It uses the Go template syntax to insert data from the feature flag manifest into the appropriate places in the template. The language.go file processes this template and fills in the data to produce the final code.
Example Workflow
- The
language.gofile reads the feature flag manifest and parses the data. - The data is processed and prepared for the template.
- The
language.gofile applies the data to thelanguage.tmplfile using the Go template engine. - The generated code is written to the appropriate output files.
By following this pattern, you can create generators for different programming languages that produce consistent and reliable code based on the feature flag manifest.
Example
Here is an example structure for a Go generator:
/internal/generators/
golang/
golang.go
golang.tmpl
Adding a New Generator
To add a new generator, follow these steps:
- Create a new directory under
/internal/generatorswith the name of the target language. - Add the
language.goandlanguage.tmplfiles to the new directory. - Implement the generator logic in the
language.gofile. - Create the template in the
language.tmplfile. - Ensure that your generator follows the existing patterns and conventions used in the project.
- Write tests for your generator to ensure it works as expected.
- Update the documentation to include information about your new generator.
We appreciate your contributions and look forward to seeing your new generators!