aboutsummaryrefslogtreecommitdiff
path: root/internal/ssh/ssh.go
diff options
context:
space:
mode:
authorᴜɴᴋɴᴡᴏɴ <u@gogs.io>2020-03-21 13:39:32 +0800
committerGitHub <noreply@github.com>2020-03-21 13:39:32 +0800
commit5843038a0812cc133c1895b7410aeda7153e8708 (patch)
tree3515998242443e1a82217ee4702603819c5315c8 /internal/ssh/ssh.go
parent958d8b6bb4c2da66859325695b91d871e567a4fa (diff)
workflows: enable golangci-lint (#5998)
* Create golint.yml * Update golint.yml * Update golint.yml * Fix errcheck * Fix gosimple * Fix staticcheck
Diffstat (limited to 'internal/ssh/ssh.go')
-rw-r--r--internal/ssh/ssh.go22
1 files changed, 14 insertions, 8 deletions
diff --git a/internal/ssh/ssh.go b/internal/ssh/ssh.go
index 50f79fef..a4d41d0f 100644
--- a/internal/ssh/ssh.go
+++ b/internal/ssh/ssh.go
@@ -33,7 +33,7 @@ func cleanCommand(cmd string) string {
func handleServerConn(keyID string, chans <-chan ssh.NewChannel) {
for newChan := range chans {
if newChan.ChannelType() != "session" {
- newChan.Reject(ssh.UnknownChannelType, "unknown channel type")
+ _ = newChan.Reject(ssh.UnknownChannelType, "unknown channel type")
continue
}
@@ -44,7 +44,9 @@ func handleServerConn(keyID string, chans <-chan ssh.NewChannel) {
}
go func(in <-chan *ssh.Request) {
- defer ch.Close()
+ defer func() {
+ _ = ch.Close()
+ }()
for req := range in {
payload := cleanCommand(string(req.Payload))
switch req.Type {
@@ -91,17 +93,19 @@ func handleServerConn(keyID string, chans <-chan ssh.NewChannel) {
return
}
- req.Reply(true, nil)
- go io.Copy(input, ch)
- io.Copy(ch, stdout)
- io.Copy(ch.Stderr(), stderr)
+ _ = req.Reply(true, nil)
+ go func() {
+ _, _ = io.Copy(input, ch)
+ }()
+ _, _ = io.Copy(ch, stdout)
+ _, _ = io.Copy(ch.Stderr(), stderr)
if err = cmd.Wait(); err != nil {
log.Error("SSH: Wait: %v", err)
return
}
- ch.SendRequest("exit-status", false, []byte{0, 0, 0, 0})
+ _, _ = ch.SendRequest("exit-status", false, []byte{0, 0, 0, 0})
return
default:
}
@@ -165,7 +169,9 @@ func Listen(host string, port int, ciphers []string) {
keyPath := filepath.Join(conf.Server.AppDataPath, "ssh", "gogs.rsa")
if !com.IsExist(keyPath) {
- os.MkdirAll(filepath.Dir(keyPath), os.ModePerm)
+ if err := os.MkdirAll(filepath.Dir(keyPath), os.ModePerm); err != nil {
+ panic(err)
+ }
_, stderr, err := com.ExecCmd(conf.SSH.KeygenPath, "-f", keyPath, "-t", "rsa", "-m", "PEM", "-N", "")
if err != nil {
panic(fmt.Sprintf("Failed to generate private key: %v - %s", err, stderr))