suborbital / sdk

Plugin libraries for languages supported by Suborbital E2 Core
Apache License 2.0
1 stars 1 forks source link

Make tinygo Plugin a Closure #5

Open rnpridgeon opened 1 year ago

rnpridgeon commented 1 year ago

Using a first class function definition, as opposed to an interface, provides greater flexibility and reduces makes templating simpler.

If a plugin/template author wishes to use a struct to attach state to their function they are still free to do so.

It is not however possible currently to supply just a function matching the appropriate signature.

// The Plugin interface is all that needs to be implemented by an E2 Core plugin.
type Plugin interface {
    Run(input []byte) ([]byte, error)
}

to

type Plugin func(input []byte) ([]byte, error)

This also simplifies template handling on the builder side since we no longer have a hard dependency on the name and shape of the target plugin.

Lastly this arrangement would more closely align with the javascript and typescript sdk.

rnpridgeon commented 1 year ago

*This change should be applied to rust as well for the same reasons stated for tinygo