| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package backends
- func init() {
- backends["dummy"] = &AbstractBackend{}
- debuggercb := &DecoratorCallbacks{}
- headerCB := &DecoratorCallbacks{}
- redisCB := &DecoratorCallbacks{}
- backends["dummy"].SetProcessors(
- MySql(), Redis(redisCB), Compressor(), Header(headerCB), Hasher(), Debugger(debuggercb), HeadersParser())
- backends["dummy"].AddConfigLoader(debuggercb.loader)
- backends["dummy"].AddConfigLoader(headerCB.loader)
- backends["dummy"].AddConfigLoader(redisCB.loader)
- }
- // custom configuration we will parse from the json
- // see guerrillaDBAndRedisConfig struct for a more complete example
- type dummyConfig struct {
- LogReceivedMails bool `json:"log_received_mails"`
- }
- // putting all the paces we need together
- type DummyBackend struct {
- config dummyConfig
- // embed functions form AbstractBackend so that DummyBackend satisfies the Backend interface
- AbstractBackend
- }
- // Backends should implement this method and set b.config field with a custom config struct
- // Therefore, your implementation would have a custom config type instead of dummyConfig
- func (b *DummyBackend) loadConfig(backendConfig BackendConfig) (err error) {
- // Load the backend config for the backend. It has already been unmarshalled
- // from the main config file 'backend' config "backend_config"
- // Now we need to convert each type and copy into the dummyConfig struct
- configType := baseConfig(&dummyConfig{})
- bcfg, err := b.extractConfig(backendConfig, configType)
- if err != nil {
- return err
- }
- m := bcfg.(*dummyConfig)
- b.config = *m
- return nil
- }
|