hcl
hcl copied to clipboard
Add BlockMarshaler and ExpressionMarshaler interfaces
Hello! This addresses my feature request in #607 . Internally we have a need for this as we want to be able to implement custom types that either emit raw, unescaped HCL, and be able to encode map[string]string to HCL easily.
These 2 interfaces let us implement the custom marshalling logic in our code while introducing minimal changes to this library code.
I added a few tests in encode_test.go to demonstrate using these interfaces to overwrite expression and block marshaling behavior on custom types, as well as some tests for handling pointer, nil and zero cases (nil and zero will panic - i think this desired behavior)
Let me know what you think - thanks!
Great feature! That can make encoding to HCL really powerful and let us implement custom encoding the same way we do JSON\YAML marshallers.
It would be great if maintainers could take a look and eventually merge it.