aluttik / go-crossplane

An unofficial Go port of the NGINX config/JSON converter crossplane
Apache License 2.0
50 stars 15 forks source link

Expose function to unmarshal/parse []byte instead of accepting path to file #9

Closed freddd closed 1 year ago

freddd commented 3 years ago

Hi,

In order to use this as a library it would be super useful to expose a function that would look something like:

func Parse(data []byte, options *ParseOptions) (*Payload, error)

or to follow common practice:

func Unmarshal(data []byte, v interface{}) error {

My main use case right now is to create a PR in https://www.conftest.dev/ in order to write policies to verify nginx configurations to find misconfigurations like those described here: https://blog.detectify.com/2020/11/10/common-nginx-misconfigurations/

freddd commented 3 years ago

Ping @aluttik

aluttik commented 3 years ago

Yeah, that would be nice. The reason it doesn't currently is because Parse will look into other files and stuff on the filesystem if the given file has an include directive. Another function like "ParseBytes" or something might be the best way to go about this that just ignores include behavior.

Anyway, this port is just a copy from the Python version like line for line I did in a weekend for fun, so it definitely isn't idiomatic Go. If you want to write up a PR or fork this then I'd be all for it 🙂

freddd commented 3 years ago

Ah ok! Makes sense. I will look into creating a PR for it.