dummy.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. // helps with worker management
  19. helper
  20. }
  21. // Backends should implement this method and set b.config field with a custom config struct
  22. // Therefore, your implementation would have a custom config type instead of dummyConfig
  23. func (b *DummyBackend) loadConfig(backendConfig BackendConfig) (err error) {
  24. // Load the backend config for the backend. It has already been unmarshalled
  25. // from the main config file 'backend' config "backend_config"
  26. // Now we need to convert each type and copy into the dummyConfig struct
  27. configType := baseConfig(&dummyConfig{})
  28. bcfg, err := b.extractConfig(backendConfig, configType)
  29. if err != nil {
  30. return err
  31. }
  32. m := bcfg.(*dummyConfig)
  33. b.config = *m
  34. return nil
  35. }