github.com/yandex/pandora@v0.5.32/core/plugin/doc.go (about)

     1  // Package plugin provides a generic inversion of control model for making
     2  // extensible Go packages, libraries, and applications. Like
     3  // github.com/progrium/go-extpoints, but reflect based: doesn't require code
     4  // generation, but have more overhead; provide more flexibility, but less type
     5  // safety. It allows to register constructor for some plugin interface, and create
     6  // new plugin instances or plugin instance factories.
     7  // Main feature is flexible plugin configuration: plugin factory can
     8  // accept config struct, that could be filled by passed hook. Config default
     9  // values could be provided by registering default config factory.
    10  // Such flexibility can be used to decode structured text (json/yaml/etc) into
    11  // struct.
    12  //
    13  // Type expectations.
    14  // Here and bellow we mean by <someTypeName> some type expectations.
    15  // [some type signature part] means that this part of type signature is optional.
    16  //
    17  // Plugin type, let's label it as <plugin>, should be interface.
    18  // Registered plugin constructor should be one of: <newPlugin> or <newFactory>.
    19  // <newPlugin> should have type func([config <configType>]) (<pluginImpl>[, error]).
    20  // <newFactory> should have type func([config <configType]) (func() (<pluginImpl>[, error])[, error]).
    21  // <pluginImpl> should be assignable to <plugin>.
    22  // That is, <plugin> methods should be subset <pluginImpl> methods. In other words, <pluginImpl> should be
    23  // some <plugin> implementation, <plugin> or interface, that contains <plugin> methods as subset.
    24  // <configType> type should be struct or struct pointer.
    25  package plugin