Main function improved

- More explicit cli operation
- Using ctx and os.Args injected for eventual later testing
- Returning exit code
- Cli code moved to cli package
This commit is contained in:
Quentin McGaw
2020-06-02 23:03:18 +00:00
parent a7739b6f5d
commit 3ab1298b1f
2 changed files with 28 additions and 11 deletions

24
internal/cli/cli.go Normal file
View File

@@ -0,0 +1,24 @@
package cli
import (
"fmt"
"strings"
"time"
"github.com/qdm12/golibs/network/connectivity"
)
func HealthCheck() error {
// DNS, HTTP and HTTPs check on github.com
connectivity := connectivity.NewConnectivity(3 * time.Second)
errs := connectivity.Checks("github.com")
if len(errs) > 0 {
var errsStr []string
for _, err := range errs {
errsStr = append(errsStr, err.Error())
}
return fmt.Errorf("Multiple errors: %s", strings.Join(errsStr, "; "))
}
// TODO check IP address is in the right region
return nil
}