dummy.go 1.2 KB

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