Documentation ¶
Overview ¶
The config package contains the API needed to make your plugin configurable.
Making your plugin available in the config file ¶
To be used in the config file, your plugin must implement the Builder interface, where it will be provided a Config object, which allows the plugin programmer to load JSON into an annotated struct of their choice, using ConfigSet's ParseConfig() method. From there, you can configure your Producer as you see fit with your user-provided configuration.
I have followed an API similar to that of golang's own database/sql. When writing your plugin, you will need to register yourself in an init() method in your package, and then the ConfigSet object will be aware of your plugin and will use it when given the corresponding key.
After registering, you need to include your package as an anonymous import in the main function which parses the config file - you can find it in cmd/goi3bar
Builder ¶
Build() is the method that is required to implement the Builder interface. It is provided a Config object, which offers ParseConfig() to cast the options subtree of your plugin's JSON block to a struct a-la json.Unmarshal. The Config object also has the raw interface{} of the options subtree, allowing you to inspect it manually, so you can provide a flexible API without the overhead of remarshalling through trial-and-error. See the network builders for an example of this.
I have defined an interface instead of a simple function typedef because there are some opportunities for code re-use. See the CPU builder for an example.
Get involved ¶
If you write something you think is really nifty, you are of course welcome to submit a pull request to me for consideration to have it included in the default distribution.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Builder ¶
Builder is the interface that must be implemented by plugins that wish to be configurable with I3bar's JSON configuration. Its' Build() method will be called exactly once on start with the given config. The Builder is strongly advised (though not required) to take advantage of the Config's ParseConfig() method, which parses the JSON options struct into a struct of their choosing. It behaves exactly like json.Unmarshal.
type Config ¶
type Config struct { Package string `json:"package"` Name string `json:"name"` Options json.RawMessage `json:"options"` }
Config for one individual plugin instance
func (Config) ParseConfig ¶
ParseConfig is the point where your plugin's JSON config subtree will be parsed. Call this function with a pointer to your JSON-annotated config struct type in here, and it will behave as you expect it to.
type ConfigSet ¶
type ConfigSet struct { Entries []Config `json:"entries"` Interval string `json:"interval"` Colors Colors `json:"colors"` }
ConfigSet represents an entire JSON config file. If all goes well, it creates an I3bar.
func ReadConfigSet ¶
ReadConfigSet reads the JSON file referenced at path, and returns a ConfigSet representing that configuration