-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #51 We now have separate "storage" and "exported" types defined for STEF data types. For most types they are equivalent except for Enums where the "storage" type is uint64, while "exported" type is user defined. The generated code now uses either "storage" or "exported" type, depending on the context and converts between the types as needed. The Metric.Type field now uses enum code generation. Previously manually created enums.go is deleted. enums.go also contains MetricFlags which is not an enum that we want to generate so it was moved to internal/metricflags.go. I will need to refactor internal/metricflags.go, but will do it in a future PR to keep the size of this PR manageable. The generator needs more tests to verify how it works with enums in other data types (oneof,array,multimap). We need to add a better test suite for generator in the future.
- Loading branch information
1 parent
33c3f69
commit e8a6f46
Showing
18 changed files
with
295 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package generator | ||
|
||
import "strings" | ||
|
||
func (g *Generator) oEnums() error { | ||
for _, enum := range g.compiledSchema.Enums { | ||
err := g.oEnum(enum) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return g.lastErr | ||
} | ||
|
||
func (g *Generator) oEnum(enum *genEnumDef) error { | ||
fields := []any{} | ||
|
||
for _, field := range enum.Fields { | ||
fieldData := map[string]any{ | ||
"Name": field.Name, | ||
"Value": field.Value, | ||
} | ||
|
||
fields = append(fields, fieldData) | ||
} | ||
|
||
data := map[string]any{ | ||
"EnumName": enum.Name, | ||
"Fields": fields, | ||
} | ||
|
||
templateName := "enum.go.tmpl" | ||
|
||
if err := g.oTemplate(templateName, strings.ToLower(enum.Name), data); err != nil { | ||
return err | ||
} | ||
|
||
return g.lastErr | ||
} |
Oops, something went wrong.