-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Italo Vietro
committed
Jul 12, 2018
0 parents
commit 2d27c0b
Showing
12 changed files
with
527 additions
and
0 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
vendor/ |
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,66 @@ | ||
# Contributing to Reachable | ||
|
||
:+1::tada: First off, thanks for taking the time to contribute! :tada::+1: | ||
|
||
The following is a set of guidelines for contributing to Reachable and its packages, | ||
which are hosted on [Github](https://github.com/italolelis) on GitHub. | ||
These are just guidelines, not rules. Use your best judgment, and feel free to propose changes | ||
to this document in a pull request. | ||
|
||
## Code of Conduct | ||
|
||
This project adheres to the Contributor Covenant [code of conduct](CODE_OF_CONDUCT.md). | ||
By participating, you are expected to uphold this code. | ||
Please report unacceptable behavior to [italolelis@gmail.com](mailto:italolelis@gmail.com). | ||
|
||
We accept contributions via Pull Requests on [Github](https://github.com/italolelis/reachable). | ||
|
||
## How Can I Contribute? | ||
|
||
### Reporting Bugs | ||
|
||
This section guides you through submitting a bug report for Reachable. Following these guidelines helps maintainers | ||
and the community understand your report :pencil:, reproduce the behavior :computer: :computer:, and find related | ||
reports :mag_right:. | ||
|
||
Before creating bug reports, please check if the bug was already reported before as you might find out that you don't | ||
need to create one. When you are creating a bug report, please [include as many details as possible](#how-do-i-submit-a-good-bug-report). | ||
|
||
#### How Do I Submit A (Good) Bug Report? | ||
|
||
Bugs are tracked as [GitHub issues](https://guides.github.com/features/issues/). Create an issue on provide the following information. | ||
|
||
Explain the problem and include additional details to help maintainers reproduce the problem: | ||
|
||
* **Use a clear and descriptive title** for the issue to identify the problem. | ||
* **Describe the exact steps which reproduce the problem** in as many details as possible. For example, start by explaining how you started Reachable, | ||
e.g. which command exactly you used in the terminal. When listing steps, **don't just say what you did, but explain how you did it**. | ||
* **Provide specific examples to demonstrate the steps**. Include links to files or GitHub projects, or copy/pasteable snippets, which you use in those examples. | ||
If you're providing snippets in the issue, use [Markdown code blocks](https://help.github.com/articles/markdown-basics/#multiple-lines). | ||
* **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior. | ||
* **Explain which behavior you expected to see instead and why.** | ||
|
||
Include details about your configuration and environment: | ||
|
||
* **Which version of Reachable are you using?** | ||
* **What's the name and version of the OS you're using**? | ||
|
||
### Your First Code Contribution | ||
|
||
Unsure where to begin contributing to Reachable? You can start by looking through these `beginner` and `help-wanted` issues: | ||
|
||
* [Beginner issues][beginner] - issues which should only require a few lines of code, and a test or two. | ||
* [Help wanted issues][help-wanted] - issues which should be a bit more involved than `beginner` issues. | ||
|
||
Both issue lists are sorted by total number of comments. While not perfect, number of comments is a reasonable proxy for impact a given change will have. | ||
|
||
### Pull Requests | ||
|
||
* Include screenshots and animated GIFs in your pull request whenever possible. | ||
* Follow the [Go](https://github.com/golang/go/wiki/CodeReviewComments) styleguides. | ||
* Include thoughtfully-worded, well-structured tests. | ||
* Document new code | ||
* End files with a newline. | ||
|
||
|
||
Happy Coding! |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,62 @@ | ||
# Gopkg.toml example | ||
# | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
# | ||
# [prune] | ||
# non-go = false | ||
# go-tests = true | ||
# unused-packages = true | ||
|
||
|
||
[[constraint]] | ||
name = "github.com/gojektech/heimdall" | ||
version = "3.0.1" | ||
|
||
[[constraint]] | ||
branch = "master" | ||
name = "github.com/hashicorp/errwrap" | ||
|
||
[[constraint]] | ||
branch = "master" | ||
name = "github.com/mitchellh/go-homedir" | ||
|
||
[[constraint]] | ||
name = "github.com/sirupsen/logrus" | ||
version = "1.0.5" | ||
|
||
[[constraint]] | ||
name = "github.com/spf13/cobra" | ||
version = "0.0.3" | ||
|
||
[[constraint]] | ||
name = "github.com/spf13/viper" | ||
version = "1.0.2" | ||
|
||
[prune] | ||
go-tests = true | ||
unused-packages = true | ||
|
||
[[constraint]] | ||
branch = "master" | ||
name = "golang.org/x/sync" | ||
|
||
[[constraint]] | ||
name = "github.com/tcnksm/go-httpstat" | ||
version = "0.2.0" |
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,63 @@ | ||
NO_COLOR=\033[0m | ||
OK_COLOR=\033[32;01m | ||
ERROR_COLOR=\033[31;01m | ||
WARN_COLOR=\033[33;01m | ||
|
||
# The import path is the unique absolute name of your repository. | ||
# All subpackages should always be imported as relative to it. | ||
# If you change this, run `make clean`. | ||
PKG_SRC := github.com/italolelis/reachable | ||
|
||
.PHONY: all clean deps build | ||
|
||
all: clean deps test build | ||
|
||
deps: | ||
@echo "$(OK_COLOR)==> Installing dependencies$(NO_COLOR)" | ||
@go get -u github.com/golang/dep/cmd/dep | ||
@go get -u github.com/golang/lint/golint | ||
@dep ensure -vendor-only | ||
|
||
build: | ||
@echo "$(OK_COLOR)==> Building... $(NO_COLOR)" | ||
CGO_ENABLED=0 go build -ldflags "-s -w" -ldflags "-X cmd.version=$(VERSION)" -o "dist/reachable" $(PKG_SRC) | ||
|
||
test: lint format vet | ||
@echo "$(OK_COLOR)==> Running tests$(NO_COLOR)" | ||
@go test -v -cover ./... | ||
|
||
format: | ||
@echo "$(OK_COLOR)==> checking code formating with 'gofmt' tool$(NO_COLOR)" | ||
@gofmt -l -s cmd pkg | grep ".*\.go"; if [ "$$?" = "0" ]; then exit 1; fi | ||
|
||
vet: | ||
@echo "$(OK_COLOR)==> checking code correctness with 'go vet' tool$(NO_COLOR)" | ||
@go vet ./... | ||
|
||
lint: tools.golint | ||
@echo "$(OK_COLOR)==> checking code style with 'golint' tool$(NO_COLOR)" | ||
@go list ./... | xargs -n 1 golint -set_exit_status | ||
|
||
clean: | ||
@echo "$(OK_COLOR)==> Cleaning project$(NO_COLOR)" | ||
@go clean | ||
@rm -rf bin $GOPATH/bin | ||
|
||
#--------------- | ||
#-- tools | ||
#--------------- | ||
|
||
.PHONY: tools tools.dep tools.golint | ||
tools: tools.dep tools.golint | ||
|
||
tools.golint: | ||
@command -v golint >/dev/null ; if [ $$? -ne 0 ]; then \ | ||
echo "--> installing golint"; \ | ||
go get github.com/golang/lint/golint; \ | ||
fi | ||
|
||
tools.dep: | ||
@command -v dep >/dev/null ; if [ $$? -ne 0 ]; then \ | ||
echo "--> installing dep"; \ | ||
@go get -u github.com/golang/dep/cmd/dep; \ | ||
fi |
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,28 @@ | ||
# Reachable | ||
|
||
> A CLI tool to check if a domain is up | ||
Welcome to reachable a CLI tool that helps you to check if a domain is up or down. | ||
|
||
## Installation | ||
|
||
Just go the [releases](https://github.com/italolelis/reachable/releases) and download the latest one for your platform. | ||
|
||
Just place the binary in your $PATH and you are good to go. | ||
|
||
## Usage | ||
|
||
``` | ||
reachable [command] [--flags] | ||
``` | ||
|
||
### Commands | ||
|
||
| Command | Description | | ||
|--------------------------|--------------------------------------| | ||
| `reachable check [--flags]` | Checks if a domain is reachable | | ||
| `reachable version` | Prints the version information | | ||
|
||
# Contributing | ||
|
||
To start contributing, please check [CONTRIBUTING](CONTRIBUTING) |
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,41 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/italolelis/reachable/pkg/log" | ||
"github.com/italolelis/reachable/pkg/reachable" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewCheckCmd creates a new check command | ||
func NewCheckCmd(ctx context.Context, timeout time.Duration) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "check", | ||
Short: "Checks if a domain is reachable", | ||
Aliases: []string{"v"}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
logger := log.WithContext(ctx) | ||
|
||
result, err := reachable.IsReachable(ctx, args[0], timeout) | ||
if err != nil { | ||
logger.Debug(err.Error()) | ||
logger.Error("Not Reachable!") | ||
return | ||
} | ||
|
||
logger.Debugf("Domain %s", result.Domain) | ||
logger.Debugf("IP %s", result.IP) | ||
logger.Debugf("Status Code %d", result.StatusCode) | ||
logger.Debugf("DNS Lookup %d ms", int(result.Response.DNSLookup/time.Millisecond)) | ||
logger.Debugf("TCP Connection %d ms", int(result.Response.TCPConnection/time.Millisecond)) | ||
logger.Debugf("TLS Handshake %d ms", int(result.Response.TLSHandshake/time.Millisecond)) | ||
logger.Debugf("Server Processing %d ms", int(result.Response.ServerProcessing/time.Millisecond)) | ||
logger.Debugf("Content Transfer %d ms", int(result.Response.ContentTransfer(time.Now())/time.Millisecond)) | ||
logger.Debugf("Total Time %d ms", int(result.Response.Total(time.Now())/time.Millisecond)) | ||
|
||
logger.Info("Reachable!") | ||
}, | ||
} | ||
} |
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,43 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/italolelis/reachable/pkg/log" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type ( | ||
// RootOptions represents the ahoy global options | ||
RootOptions struct { | ||
timeout time.Duration | ||
verbose bool | ||
} | ||
) | ||
|
||
// NewRootCmd creates the root command | ||
func NewRootCmd() *cobra.Command { | ||
opts := RootOptions{} | ||
ctx := log.NewContext(context.Background()) | ||
|
||
cmd := cobra.Command{ | ||
Use: "reachable", | ||
Short: "Reachable is a CLI tool to check if a domain is up", | ||
PersistentPreRun: func(ccmd *cobra.Command, args []string) { | ||
if opts.verbose { | ||
log.WithContext(context.Background()).SetLevel(logrus.DebugLevel) | ||
} | ||
}, | ||
} | ||
|
||
cmd.PersistentFlags().DurationVarP(&opts.timeout, "timeout", "t", 30*time.Second, "Defines a timeout") | ||
cmd.PersistentFlags().BoolVarP(&opts.verbose, "verbose", "v", false, "Make the operation more talkative") | ||
|
||
// Aggregates Root commands | ||
cmd.AddCommand(NewCheckCmd(ctx, opts.timeout)) | ||
cmd.AddCommand(NewVersionCmd(ctx)) | ||
|
||
return &cmd | ||
} |
Oops, something went wrong.