graniticio / granitic

Web/micro-services and IoC framework for Golang developers
https://granitic.io/
Apache License 2.0
35 stars 12 forks source link

Allow libraries to define their own facilities #59

Open benhalstead opened 4 years ago

benhalstead commented 4 years ago

Summary

Allow third-party library developers to create facilities that will behave in similar way to Granitic's built-in facilities:

Background

Third party libraries for Granitic applications can provide code and component definitions which are linked to the application during the grnc-bind phase of the build process via a command line argument giving the absolute path to the library code. This quickly gets unwieldy with more than a couple of dependencies and has a number of other problems:

The solution to this problem is to allow libraries to declare themselves as defining one or more facilities. grnc-bind will then scan all first-order dependencies in an application's go.mod file to see if they contain facilities and include those facilities (code and default configuration) in the generated binding file.

Implementation

A library will have a folder facility at the top level. If this folder contains a file facilities.json (or .yml) the library will be considered to have one or more facilities.

The default configuration for the facilities will be expected to be in either facility/config.json or facility/config/*json (or YAML equivalents)

The component definition for the facilities will be expected to be in either facility/comp.json or facility/comp/*json (or YAML equivalents)

The facilities.json file will look like:

{
  "FacilityNameA": {
    "FacilityBuilder": "package/type",
    "DependsOn": ["other", "facilities"],
    "Enabled": true
  },
  "FacilityNameB": {
    "FacilityBuilder": "package/othertype",
    "DependsOn": ["other", "facilities"],
    "Enabled": false
  },
}

For example:

{
  "RequestProfiler": {
    "FacilityBuilder": "profiling/FacilityBuilder",
    "DependsOn": ["HTTPServer"],
    'Enabled": false
  }
}

Where

Compatibility