Skip to content

Generated structs could rely on structs instead of struct pointers #50

@eli-l

Description

@eli-l

Hi,

I noticed every time I generate my Go structs, regardless of definitions inside .pkl files Go structs always contains struct pointers, never structs.

When I have structs generated from one type of config with pkl-gen-go and later on I pass a different Pkl module, that might not provide values for the generated structs - it is causing fatal, because I am trying to access property on nil.

It would be good to have a possibility to generate structs based on structs, than such attempt to access would return a default value for the type, like 0 or "". This could provide an easier way to fallback or fail, but not panic.

With current implementation it requires me to check all structs being nil embedded to my main Config struct, no matter whether default type value matches me.

Summing up:
When valid Pkl module is loaded to the Go structs generated by pkl-gen-go it may lead to property being nil and and either triggers panic or requires additional validation.

Proposal: provide a mechanism to decide between Type.Pointer and Type.Declared when generating structs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions