diff options
| author | Marin Ivanov <[email protected]> | 2025-04-16 19:18:02 +0300 |
|---|---|---|
| committer | Marin Ivanov <[email protected]> | 2025-04-16 19:18:02 +0300 |
| commit | 0fefc0f6c69663615025074ac2184508802d4b9d (patch) | |
| tree | 44f441189a3725604376b6285b1c77326fb34efc | |
| parent | 1a339a82fe6209e463029e433a254e6d237fa17c (diff) | |
| -rw-r--r-- | Dockerfile | 2 | ||||
| -rw-r--r-- | handle.go | 14 | ||||
| -rw-r--r-- | main.go | 2 | ||||
| -rw-r--r-- | setuid_unix.go | 1 | ||||
| -rw-r--r-- | setuid_windows.go | 1 |
5 files changed, 10 insertions, 10 deletions
@@ -1,4 +1,4 @@ -FROM golang:1.12-alpine as builder +FROM golang:1.12-alpine AS builder WORKDIR /app COPY . /app RUN apk add --no-cache git make \ @@ -2,6 +2,7 @@ package main import ( "fmt" + "log" "net" "time" ) @@ -20,15 +21,12 @@ func protocolHandler(proto string) (protoHandler, uint16, error) { } } -func logConn(conn net.Conn, msg string) { - now := time.Now().UTC() - fmt.Printf("%s, %s, %s\n", now.String(), conn.RemoteAddr().String(), msg) -} - -func connHandler(handler protoHandler, conn net.Conn, delay time.Duration) { +func connHandler(proto string, handler protoHandler, conn net.Conn, delay time.Duration) { defer conn.Close() - logConn(conn, "handling") + start := time.Now() + log.Printf("%s handling %s", conn.RemoteAddr().String(), proto) handler(conn, delay) - logConn(conn, "closing") + duration := time.Since(start) + log.Printf("%s ended %s lasted for %s", conn.RemoteAddr().String(), proto, duration) } @@ -67,7 +67,7 @@ func main() { if err != nil { continue } - go connHandler(handler, conn, delay) + go connHandler(protocol, handler, conn, delay) } } diff --git a/setuid_unix.go b/setuid_unix.go index 8782a48..5db6746 100644 --- a/setuid_unix.go +++ b/setuid_unix.go @@ -1,3 +1,4 @@ +//go:build linux || darwin // +build linux darwin package main diff --git a/setuid_windows.go b/setuid_windows.go index 277ed12..e818eb8 100644 --- a/setuid_windows.go +++ b/setuid_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package main |
