-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from hellofresh/feature-improvements
Check improvements
- Loading branch information
Showing
10 changed files
with
94 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ before_install: | |
|
||
install: | ||
- mkdir -p $GOPATH/bin | ||
- make deps | ||
|
||
script: | ||
- make all | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,21 +6,56 @@ import ( | |
"time" | ||
|
||
"github.com/hellofresh/health-go" | ||
healthHttp "github.com/hellofresh/health-go/checks/http" | ||
healthMySql "github.com/hellofresh/health-go/checks/mysql" | ||
healthPg "github.com/hellofresh/health-go/checks/postgres" | ||
) | ||
|
||
func main() { | ||
// custom health check example (fail) | ||
health.Register(health.Config{ | ||
Name: "rabbitmq", | ||
Name: "some-custom-check-fail", | ||
Timeout: time.Second * 5, | ||
SkipOnErr: true, | ||
Check: func() error { return errors.New("Failed duriung rabbitmq health check") }, | ||
Check: func() error { return errors.New("failed during rabbitmq health check") }, | ||
}) | ||
|
||
// custom health check example (success) | ||
health.Register(health.Config{ | ||
Name: "mongodb", | ||
Name: "some-custom-check-success", | ||
Check: func() error { return nil }, | ||
}) | ||
|
||
// http health check example | ||
health.Register(health.Config{ | ||
Name: "http-check", | ||
Timeout: time.Second * 5, | ||
SkipOnErr: true, | ||
Check: healthHttp.New(healthHttp.Config{ | ||
URL: `http://example.com`, | ||
}), | ||
}) | ||
|
||
// postgres health check example | ||
health.Register(health.Config{ | ||
Name: "postgres-check", | ||
Timeout: time.Second * 5, | ||
SkipOnErr: true, | ||
Check: healthPg.New(healthPg.Config{ | ||
DSN: `postgres://test:[email protected]:32807/test?sslmode=disable`, | ||
}), | ||
}) | ||
|
||
// mysql health check example | ||
health.Register(health.Config{ | ||
Name: "mysql-check", | ||
Timeout: time.Second * 5, | ||
SkipOnErr: true, | ||
Check: healthMySql.New(healthMySql.Config{ | ||
DSN: `test:test@tcp(0.0.0.0:32802)/test?charset=utf8`, | ||
}), | ||
}) | ||
|
||
http.Handle("/status", health.Handler()) | ||
http.ListenAndServe(":3000", nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package http | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
const httpURLEnv = "HEALTH_GO_HTTP_URL" | ||
|
||
func TestNew(t *testing.T) { | ||
if os.Getenv(httpURLEnv) == "" { | ||
t.SkipNow() | ||
} | ||
|
||
check := New(Config{ | ||
URL: os.Getenv(httpURLEnv), | ||
}) | ||
|
||
if err := check(); err != nil { | ||
t.Fatalf("HTTP check failed: %s", err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.