52 lines
1.8 KiB
Go
52 lines
1.8 KiB
Go
package reachview
|
|
|
|
import "context"
|
|
|
|
const (
|
|
eventGetConfiguration = "get configuration"
|
|
eventCurrentConfiguration = "current configuration"
|
|
eventApplyConfiguration = "apply configuration"
|
|
eventConfigurationApplied = "configuration applied"
|
|
eventResetConfiguration = "reset configuration to default"
|
|
)
|
|
|
|
// Configuration fetches and return the current configuration of the ReachRS module
|
|
func (r *Client) Configuration(ctx context.Context) (*Configuration, error) {
|
|
configuration := &Configuration{}
|
|
if err := r.ReqResp(ctx, eventGetConfiguration, nil, eventCurrentConfiguration, configuration); err != nil {
|
|
return nil, err
|
|
}
|
|
return configuration, nil
|
|
}
|
|
|
|
type configurationApplied struct {
|
|
Configuration *Configuration `mapstructure:"configuration,omitempty"`
|
|
Result string `mapstructure:"result"`
|
|
Constraints *Constraints `mapstructure:"Constraints,omitempty"`
|
|
}
|
|
|
|
const (
|
|
// ConfigurationApplySuccess -
|
|
ConfigurationApplySuccess = "success"
|
|
// ConfigurationApplyFailed -
|
|
ConfigurationApplyFailed = "failed"
|
|
)
|
|
|
|
// ApplyConfiguration applies the given configuration
|
|
func (r *Client) ApplyConfiguration(ctx context.Context, config *Configuration) (string, *Configuration, error) {
|
|
res := &configurationApplied{}
|
|
if err := r.ReqResp(ctx, eventApplyConfiguration, config, eventConfigurationApplied, res); err != nil {
|
|
return ConfigurationApplyFailed, nil, err
|
|
}
|
|
return res.Result, res.Configuration, nil
|
|
}
|
|
|
|
// ResetConfiguration resets the module configuration to factory defaults
|
|
func (r *Client) ResetConfiguration(ctx context.Context) (string, *Configuration, error) {
|
|
res := &configurationApplied{}
|
|
if err := r.ReqResp(ctx, eventResetConfiguration, nil, eventConfigurationApplied, res); err != nil {
|
|
return ConfigurationApplyFailed, nil, err
|
|
}
|
|
return res.Result, res.Configuration, nil
|
|
}
|