Skip to content

Commit

Permalink
Prepare for version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
outdead committed Oct 5, 2020
1 parent 6c8d58f commit ba1c104
Show file tree
Hide file tree
Showing 7 changed files with 611 additions and 21 deletions.
25 changes: 20 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ output:
print-issued-lines: true
print-linter-name: true

# SEE: https://golangci-lint.run/usage/configuration/
linters-settings:
dupl:
# tokens count to trigger issue, 150 by default
Expand All @@ -30,12 +31,12 @@ linters-settings:
check-blank: false
funlen:
# default is 60
lines: 80
lines: 60
# default is 40
statements: 40
gocognit:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 30
min-complexity: 15
goconst:
# minimal length of string constant, 3 by default
min-len: 3
Expand All @@ -48,9 +49,11 @@ linters-settings:
- experimental
disabled-checks:
- paramTypeCombine
# - whyNoLint
# - commentedOutCode
gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 20
min-complexity: 15
godox:
keywords:
- "BUG"
Expand All @@ -69,6 +72,7 @@ linters-settings:
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks: argument,case,condition,operation,return,assign
govet:
# report about shadowed variables.
check-shadowing: true
depguard:
list-type: blacklist
Expand All @@ -81,7 +85,7 @@ linters-settings:
- gopkg.in/Sirupsen/logrus.v0
- gopkg.in/Sirupsen/logrus.v1
lll:
line-length: 136 # 120 is default
line-length: 120 # 120 is default
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
Expand Down Expand Up @@ -121,6 +125,17 @@ linters-settings:
# Force newlines in end of case at this limit (0 = never).
force-case-trailing-whitespace: 0

linters:
enable-all: true
disable:

issues:
exclude:
- "`DefaultSettings` is a global variable" # (gochecknoglobals)
- "`DefaultSettings` is a global variable" # (gochecknoglobals)

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.16.x # use the fixed version to not introduce new linters unexpectedly
prepare:
- echo "here I can run custom commands, but no preparation needed for this repo"
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: go

go:
- 1.13.x
- 1.15.x
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## v1.0.0 - 2020-10-06
### Added
- Initial implementation.

[Unreleased]: https://github.com/gorcon/telnet/compare/v1.0.0...HEAD
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
)

func main() {
conn, err := telnet.Dial("172.19.0.2:8081", "banana"))
conn, err := telnet.Dial("172.19.0.2:8081", "banana")
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -72,7 +72,7 @@ func main() {

## Requirements

Go 1.13 or higher
Go 1.15 or higher

## Contribute

Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module github.com/gorcon/telnet

go 1.13
go 1.15

require github.com/stretchr/testify v1.6.1
require (
github.com/stretchr/testify v1.6.1
)
574 changes: 574 additions & 0 deletions go.sum

Large diffs are not rendered by default.

18 changes: 7 additions & 11 deletions telnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ type Conn struct {
settings Settings
reader io.Reader
writer io.Writer

w bytes.Buffer
buffer bytes.Buffer
}

// Dial creates a new authorized TELNET connection.
Expand All @@ -83,8 +82,7 @@ func Dial(address string, password string, options ...Option) (*Conn, error) {

client := Conn{conn: conn, settings: settings, reader: conn, writer: conn}

// TODO: Graceful close.
go client.processReadResponse(&client.w)
go client.processReadResponse(&client.buffer)

if err := client.auth(password); err != nil {
// Failed to auth conn with the server.
Expand Down Expand Up @@ -122,10 +120,9 @@ func DialInteractive(r io.Reader, w io.Writer, address string, password string,
}
}

// TODO: Graceful close.
go client.processReadResponse(w)

return client.interactive(r, w)
return client.interactive(r)
}

// Execute sends command string to execute to the remote TELNET server.
Expand All @@ -139,7 +136,7 @@ func (c *Conn) Execute(command string) (string, error) {

time.Sleep(ReceiveWaitPeriod)

return c.w.String(), err
return c.buffer.String(), err
}

// LocalAddr returns the local network address.
Expand Down Expand Up @@ -187,12 +184,12 @@ func (c *Conn) execute(command string) (string, error) {

time.Sleep(ExecuteTickTimeout)

return c.w.String(), nil
return c.buffer.String(), nil
}

// interactive reads commands from reader in terminal mode and sends them
// to execute to the remote TELNET server.
func (c *Conn) interactive(r io.Reader, w io.Writer) error {
func (c *Conn) interactive(r io.Reader) error {
scanner := bufio.NewScanner(r)
for scanner.Scan() {
command := scanner.Text()
Expand Down Expand Up @@ -228,8 +225,7 @@ func (c *Conn) read(p []byte) (n int, err error) {
// processReadResponse reads response data from TELNET connection
// and writes them to writer (Stdout).
func (c *Conn) processReadResponse(writer io.Writer) {
var buffer [1]byte
p := buffer[:]
p := make([]byte, 1)

for {
// Read 1 byte.
Expand Down

0 comments on commit ba1c104

Please sign in to comment.