1
0

healthcheck.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2014 beego Author. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Package toolbox healthcheck
  15. //
  16. // type DatabaseCheck struct {
  17. // }
  18. //
  19. // func (dc *DatabaseCheck) Check() error {
  20. // if dc.isConnected() {
  21. // return nil
  22. // } else {
  23. // return errors.New("can't connect database")
  24. // }
  25. // }
  26. //
  27. // AddHealthCheck("database",&DatabaseCheck{})
  28. //
  29. // more docs: http://beego.me/docs/module/toolbox.md
  30. package toolbox
  31. // AdminCheckList holds health checker map
  32. var AdminCheckList map[string]HealthChecker
  33. // HealthChecker health checker interface
  34. type HealthChecker interface {
  35. Check() error
  36. }
  37. // AddHealthCheck add health checker with name string
  38. func AddHealthCheck(name string, hc HealthChecker) {
  39. AdminCheckList[name] = hc
  40. }
  41. func init() {
  42. AdminCheckList = make(map[string]HealthChecker)
  43. }