From 59bb805ecd41ee3efdbb5777dc56712ac1649688 Mon Sep 17 00:00:00 2001 From: kamkow1 Date: Sat, 21 Jun 2025 14:55:24 +0200 Subject: [PATCH] Configurable listen port --- Makefile | 12 +++++++++++- lts.go | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 227979d..0c2ba90 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,15 @@ +BUILD_MODE ?= DEBUG + +ifeq ($(BUILD_MODE),DEBUG) + LISTEN_PORT = ":9090" +else ifeq ($(BUILD_MODE),RELEASE) + LISTEN_PORT = ":80" +else + $(error Unknown build mode) +endif + all: - go build + go build -ldflags="-X main.LISTEN_PORT=\"$(LISTEN_PORT)\"" watcher: cc -o watcher watcher.c diff --git a/lts.go b/lts.go index b993f3f..29f041f 100644 --- a/lts.go +++ b/lts.go @@ -17,6 +17,8 @@ import ( "github.com/fsnotify/fsnotify" ) +var LISTEN_PORT string + //go:embed tmpls/* var tmpls embed.FS @@ -114,6 +116,7 @@ func handleUpload(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Uploaded file: %s\n", handler.Filename) fmt.Fprintf(w, "File size: %s\n", byteCountSI(handler.Size)) + fmt.Fprintf(w, "Link: ") dst, err := createFile(storePath, handler.Filename) if err != nil { @@ -242,7 +245,7 @@ func main() { http.Handle("/etc/", http.FileServerFS(etc)) http.Handle("/store/", http.StripPrefix("/store/", http.FileServer(http.Dir(storePath)))) - http.ListenAndServe(":9090", nil) + http.ListenAndServe(LISTEN_PORT, nil) doneWatching<-true }