Saturday, May 18, 2024
HomeGolangReflection of an exterior part - Getting Assist

Reflection of an exterior part – Getting Assist


I’ve an concept for a program I wish to write, that requires some plugin performance. I wish to write it in Go, however I’m not certain whether it is potential.

Mainly I need my predominant program to have the ability to load in quite a lot of plugins, which are required to implement a particular interface. The plugins needs to be positioned in a particular plugin folder.

I’ve by no means used reflection (mirror package deal) in Go earlier than, and my preliminary search didn’t return any examples of methods to “load” a “part” from a particular path. Is that even potential in Go?

Instance in C# : reflection – Loading DLLs at runtime in C# – Stack Overflow

mainExecutable
       |
       ------- plugin folder
                    |
                    ------- plugin 1
                    |
                    ------- plugin 2
                    |
                   ...
                    ------- plugin n

Go applications compile into monolithic binaries. Usually they don’t load any dynamic dependencies into the runtime, apart from doing system calls or wrappers for third-party native libraries (database drivers, GUI, and many others.).

Your finest choices could be:

  1. Embed a scripting language like Lua and have customers write plugins in that language. Some Go applications already do this, e.g. the Micro editor.
  2. Construct plugins as separate applications (after which they don’t even must be carried out in Go) and interface with them in another approach – stdin/stdout, HTTP, and many others. I’d take a look at Language Server Protocol for example of this method.

Hmm…I used to be afraid of that…

I assume possibility 2 looks as if the way in which I must go then. Perhaps each plugin must create a JSON file, or one thing. I must take into consideration that…Thanks!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments