health.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package health
  2. import (
  3. "fmt"
  4. "github.com/abh/geodns/typeutil"
  5. )
  6. type HealthTester interface {
  7. // Test(record string) bool
  8. Name(record string) string
  9. String() string
  10. }
  11. type HealthReference struct {
  12. name string
  13. }
  14. func (hr *HealthReference) Name(record string) string {
  15. if len(record) > 0 {
  16. return hr.name + "/" + record
  17. }
  18. return hr.name
  19. }
  20. func (hr *HealthReference) String() string {
  21. return hr.name
  22. }
  23. func NewReferenceFromMap(i map[string]interface{}) (HealthTester, error) {
  24. var name, ts string
  25. if ti, ok := i["type"]; ok {
  26. ts = typeutil.ToString(ti)
  27. }
  28. if ni, ok := i["name"]; ok {
  29. name = typeutil.ToString(ni)
  30. }
  31. if len(name) == 0 {
  32. name = ts
  33. }
  34. if len(name) == 0 {
  35. return nil, fmt.Errorf("name or type required")
  36. }
  37. tester := &HealthReference{name: name}
  38. return tester, nil
  39. }
  40. // func (hr *HealthReference) RecordTest(rec *zones.Record) {
  41. // key := ht.String()
  42. // htr.entryMutex.Lock()
  43. // defer htr.entryMutex.Unlock()
  44. // if t, ok := htr.entries[key]; ok {
  45. // // we already have an instance of this test running. Record we are using it
  46. // t.references[ref] = true
  47. // } else {
  48. // // a test that isn't running. Record we are using it and start the test
  49. // t := &HealthTestRunnerEntry{
  50. // HealthTest: *ht.copy(ht.ipAddress),
  51. // references: make(map[string]bool),
  52. // }
  53. // if t.global {
  54. // t.ipAddress = nil
  55. // }
  56. // // we know it is not started, so no need for the mutex
  57. // t.healthy = ht.healthy
  58. // t.references[ref] = true
  59. // t.start()
  60. // htr.entries[key] = t
  61. // }
  62. // }