IConfigurable

An interface used to set configuration parameters to an object.

See also ConfigParams

Description

IConfigurable is an interface used to set configuration parameters. It can be implemented by any class that needs to define configuration parameters, such as access control credentials.

Important points:

  • A class that implements this interface needs to implement a single Configure() method.
  • If you need to emphasize the fact that Configure() method can be called multiple times to change object configuration in runtime, use IReconfigurable interface instead.

Methods

Configure

Configures component by passing configuration parameters.

Configure(ctx context.Context, config *ConfigParams)

  • ctx: context.Context - operation context.
  • config: *ConfigParams - configuration parameters to be set.

Examples

type MyStruct struct  {
     myParam string 
}

func NewMyStruct() *MyStruct {
    return &MyStruct{
        myParam: "default value",
    },
}

// Implement configure
func (c* MyStruct) Configure(ctx context.Context, config *cconf.ConfigParams)  {
    c.myParam = config.GetAsStringWithDefault("options.param", myParam);
    ...
}

See also