Skip to content

Commit

Permalink
fix linter errors : errors and remove unused value
Browse files Browse the repository at this point in the history
  • Loading branch information
diginatu committed Dec 16, 2017
1 parent b0b73ff commit efc4e7a
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ import (
"golang.org/x/net/websocket"
)

const (
defaultPort = "8753"
)

var (
ngmr io.ReadCloser
ngmw io.WriteCloser
Expand Down Expand Up @@ -52,15 +48,15 @@ read:
// append utf8tmp to the top of buf
copy(buf, utf8tmp)
// read into the rest buf
nr, er := src.Read(buf[len(utf8tmp):])
nr, err := src.Read(buf[len(utf8tmp):])
nr += len(utf8tmp)
utf8tmp = utf8tmp[0:0]
if nr > 0 {
rb := buf[0:nr]
if !utf8.Valid(rb) {
for i := 1; ; i++ {
if i > 4 {
panic("invalid data (not utf-8)")
return fmt.Errorf("invalid data (not utf-8)")
}
if i == nr {
utf8tmp = make([]byte, i)
Expand Down Expand Up @@ -94,11 +90,11 @@ read:
}
mu.Unlock()
}
if er == io.EOF {
if err == io.EOF {
return nil
}
if er != nil {
return er
if err != nil {
return fmt.Errorf("websocket read: %s", err.Error())
}
}

Expand Down Expand Up @@ -211,19 +207,27 @@ func cli() error {
}

go func() {
io.Copy(os.Stderr, ngme)
_, _ = io.Copy(os.Stderr, ngme)
}()

go func() {
io.Copy(ioutil.Discard, os.Stdin)
_, _ = io.Copy(ioutil.Discard, os.Stdin)
close(quit)
}()

// wait for quit
go func() {
<-quit
ngmw.Close()
cmd.Wait()
err := ngmw.Close()
if err != nil {
log.Println("nagome connection close: ", err)
os.Exit(1)
}
err = cmd.Wait()
if err != nil {
log.Println("nagome wait: ", err)
os.Exit(1)
}
fmt.Println("cmd end")
os.Exit(0)
}()
Expand Down

0 comments on commit efc4e7a

Please sign in to comment.