From a171e8418967f005b6943d769636eefe95f1a2ea Mon Sep 17 00:00:00 2001 From: Quentin Date: Sat, 20 Nov 2021 15:10:21 +0100 Subject: [PATCH] Better error management --- .dockerignore | 3 +++ Dockerfile | 3 ++- main.go | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..da1f65e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +s3_cache +.git +bagage diff --git a/Dockerfile b/Dockerfile index 861bb6a..5b059dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,8 @@ FROM golang:1.17.0-alpine3.14 as builder ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64 RUN apk update && apk add --no-cache ca-certificates && update-ca-certificates WORKDIR /opt -COPY *.go go.mod go.sum /opt/ +COPY . /opt/ +RUN ls /opt/ RUN go build . FROM scratch diff --git a/main.go b/main.go index c70dd4d..a76690e 100644 --- a/main.go +++ b/main.go @@ -97,6 +97,7 @@ func handleSSHConn(nConn net.Conn, dconfig *Config, config *ssh.ServerConfig) { serverConn, chans, reqs, err := ssh.NewServerConn(nConn, config) if err != nil { log.Printf("failed to handshake: ", err) + return } defer serverConn.Conn.Close() user := serverConn.Conn.User() @@ -120,6 +121,7 @@ func handleSSHConn(nConn net.Conn, dconfig *Config, config *ssh.ServerConfig) { channel, requests, err := newChannel.Accept() if err != nil { log.Print("could not accept channel.", err) + return } log.Printf("Channel accepted\n") @@ -155,7 +157,8 @@ func handleSSHConn(nConn net.Conn, dconfig *Config, config *ssh.ServerConfig) { server, err := sftp.NewServer(ctx, channel, &fs) if err != nil { - log.Fatal(err) + log.Println(err) + return } if err := server.Serve(); err == io.EOF {