github.com/astaxie/beego@v1.12.3/toolbox/healthcheck.go (about)

     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  
    15  // Package toolbox healthcheck
    16  //
    17  // type DatabaseCheck struct {
    18  // }
    19  //
    20  // func (dc *DatabaseCheck) Check() error {
    21  //	if dc.isConnected() {
    22  //		return nil
    23  //	} else {
    24  //		return errors.New("can't connect database")
    25  // 	 }
    26  // }
    27  //
    28  // AddHealthCheck("database",&DatabaseCheck{})
    29  //
    30  // more docs: http://beego.me/docs/module/toolbox.md
    31  package toolbox
    32  
    33  // AdminCheckList holds health checker map
    34  var AdminCheckList map[string]HealthChecker
    35  
    36  // HealthChecker health checker interface
    37  type HealthChecker interface {
    38  	Check() error
    39  }
    40  
    41  // AddHealthCheck add health checker with name string
    42  func AddHealthCheck(name string, hc HealthChecker) {
    43  	AdminCheckList[name] = hc
    44  }
    45  
    46  func init() {
    47  	AdminCheckList = make(map[string]HealthChecker)
    48  }