Add usage in README
This commit is contained in:
parent
9b0c49fe5e
commit
b1b6beb4d3
25
README.md
25
README.md
|
@ -36,6 +36,31 @@ considered as some misbehaviour of client.**
|
|||
## Requirements:
|
||||
- Linux 2.4 or newer
|
||||
|
||||
## Usage
|
||||
```go
|
||||
import "github.com/tevino/tcp-shaker"
|
||||
|
||||
s := tcp.Shaker{}
|
||||
if err := s.Init(); err != nil {
|
||||
log.Fatal("Shaker init failed:", err)
|
||||
}
|
||||
|
||||
timeout := time.Second * 1
|
||||
err := s.Test("google.com:80", timeout)
|
||||
switch err {
|
||||
case tcp.ErrTimeout:
|
||||
fmt.Println("Connect to Google timeout")
|
||||
case nil:
|
||||
fmt.Println("Connect to Google succeded")
|
||||
default:
|
||||
if e, ok := err.(*tcp.ErrConnect); ok {
|
||||
fmt.Println("Connect to Google failed:", e)
|
||||
} else {
|
||||
fmt.Println("Error occurred while connecting:", err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## TODO:
|
||||
|
||||
- [ ] IPv6 support (Test environment needed, PRs are welcomed)
|
||||
|
|
Loading…
Reference in New Issue