1. 7
  1. 1

    For expression evaluation better to use expr https://github.com/antonmedv/expr

    1. 1

      I’ve seen that! Looks great, looking forward to using it in my projects!

    2. 1

      Go has -buildmode=plugin https://golang.org/pkg/plugin/. I have been meaning to experiment a bit more with it, but it seems like a better way then on-the-fly compiling the go files?

      1. 1

        yaegi doesn’t compile scripts (it’s an interpreter). On my machine, the trivial script in this article takes 4-5ms to execute (3-4ms initialization, 1ms script running, func calling). That’s good enough for me.

        At any rate, plugins come with some limitations

        • The plugin loader and plugin must be using the exact same versions of libraries. With yaegi, you have forwards compatibility
        • They’re only supported on Linux, FreeBSD and macOS. yaegi works wherever Go works

        It depends on the kind of application you’re building. “Pro” versions are probably better done with build tags. For scripts (think mpv), requiring the Go toolchain to make plugins is a bit much. And if you do, might as well make them recompile the application - Go compiles quickly. I don’t really see a use case where plugins would work best. Even for extending proprietary applications, it would generate a lot of support load (wouldn’t be the best UX either).

        See also: https://tpaschalis.github.io/golang-plugins/

        1. 1

          Hashicorp’s go-plugin looks interesting.