dummy.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package backends
  2. func init() {
  3. backends["dummy"] = &AbstractBackend{}
  4. debuggercb := &DecoratorCallbacks{}
  5. headerCB := &DecoratorCallbacks{}
  6. redisCB := &DecoratorCallbacks{}
  7. backends["dummy"].SetProcessors(
  8. MySql(), Redis(redisCB), Compressor(), Header(headerCB), Hasher(), Debugger(debuggercb), HeadersParser())
  9. backends["dummy"].AddConfigLoader(debuggercb.loader)
  10. backends["dummy"].AddConfigLoader(headerCB.loader)
  11. backends["dummy"].AddConfigLoader(redisCB.loader)
  12. }
  13. // custom configuration we will parse from the json
  14. // see guerrillaDBAndRedisConfig struct for a more complete example
  15. type dummyConfig struct {
  16. LogReceivedMails bool `json:"log_received_mails"`
  17. }
  18. // putting all the paces we need together
  19. type DummyBackend struct {
  20. config dummyConfig
  21. // embed functions form AbstractBackend so that DummyBackend satisfies the Backend interface
  22. AbstractBackend
  23. }
  24. // Backends should implement this method and set b.config field with a custom config struct
  25. // Therefore, your implementation would have a custom config type instead of dummyConfig
  26. func (b *DummyBackend) loadConfig(backendConfig BackendConfig) (err error) {
  27. // Load the backend config for the backend. It has already been unmarshalled
  28. // from the main config file 'backend' config "backend_config"
  29. // Now we need to convert each type and copy into the dummyConfig struct
  30. configType := baseConfig(&dummyConfig{})
  31. bcfg, err := b.extractConfig(backendConfig, configType)
  32. if err != nil {
  33. return err
  34. }
  35. m := bcfg.(*dummyConfig)
  36. b.config = *m
  37. return nil
  38. }