Skip to content

Commit

Permalink
Merge pull request #15 from niima/feature/refactor
Browse files Browse the repository at this point in the history
Refactor some modules.
  • Loading branch information
ph4r5h4d authored Oct 9, 2020
2 parents 950e4e0 + fd0ddc6 commit 47ced58
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion MongoDbChecker/MongoDbChecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"wait4it/model"
)

const WaitTimeOutSeconds = 2

func (m *MongoDbConnection) BuildContext(cx model.CheckContext) {
m.Port = cx.Port
m.Host = cx.Host
Expand Down Expand Up @@ -39,7 +41,7 @@ func (m *MongoDbConnection) Check() (bool, bool, error) {
return false, true, err
}

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), WaitTimeOutSeconds*time.Second)
defer cancel()

err = client.Connect(ctx)
Expand Down
2 changes: 1 addition & 1 deletion PostgreSQLChecker/postgresqlChecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (pq *PostgresSQLConnection) Validate() (bool, error) {
}

if pq.Port < 1 || pq.Port > 65535 {
return false, errors.New("invalid port range for mysql")
return false, errors.New("invalid port range for PostgresSQL")
}

return true, nil
Expand Down
8 changes: 5 additions & 3 deletions cmd/check-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"wait4it/model"
)

const InvalidUsageStatus = 2

func RunCheck(c model.CheckContext) {
m, err := findCheckModule(c.Config.CheckType)
if err != nil {
wStdErr(err)
os.Exit(2)
os.Exit(InvalidUsageStatus)
}

cx := m.(model.CheckInterface)
Expand All @@ -21,7 +23,7 @@ func RunCheck(c model.CheckContext) {
r, err := cx.Validate()
if !r {
wStdErr(err)
os.Exit(2)
os.Exit(InvalidUsageStatus)
}

fmt.Print("Wait4it...")
Expand Down Expand Up @@ -62,7 +64,7 @@ func check(cs model.CheckInterface) {
r, eor, err := cs.Check()
if err != nil && eor {
wStdErr(err.Error())
os.Exit(2)
os.Exit(InvalidUsageStatus)
}

wStdOut(r)
Expand Down
1 change: 1 addition & 0 deletions httpChecker/httpChecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (h *HttpCheck) Check() (bool, bool, error) {
if err != nil {
return false, true, err
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
Expand Down

0 comments on commit 47ced58

Please sign in to comment.