Configurable listen port

This commit is contained in:
kamkow1
2025-06-21 14:55:24 +02:00
parent 05c0eaebaa
commit 59bb805ecd
2 changed files with 15 additions and 2 deletions

View File

@ -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: all:
go build go build -ldflags="-X main.LISTEN_PORT=\"$(LISTEN_PORT)\""
watcher: watcher:
cc -o watcher watcher.c cc -o watcher watcher.c

5
lts.go
View File

@ -17,6 +17,8 @@ import (
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
) )
var LISTEN_PORT string
//go:embed tmpls/* //go:embed tmpls/*
var tmpls embed.FS 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, "Uploaded file: %s\n", handler.Filename)
fmt.Fprintf(w, "File size: %s\n", byteCountSI(handler.Size)) fmt.Fprintf(w, "File size: %s\n", byteCountSI(handler.Size))
fmt.Fprintf(w, "Link: ")
dst, err := createFile(storePath, handler.Filename) dst, err := createFile(storePath, handler.Filename)
if err != nil { if err != nil {
@ -242,7 +245,7 @@ func main() {
http.Handle("/etc/", http.FileServerFS(etc)) http.Handle("/etc/", http.FileServerFS(etc))
http.Handle("/store/", http.StripPrefix("/store/", http.FileServer(http.Dir(storePath)))) http.Handle("/store/", http.StripPrefix("/store/", http.FileServer(http.Dir(storePath))))
http.ListenAndServe(":9090", nil) http.ListenAndServe(LISTEN_PORT, nil)
doneWatching<-true doneWatching<-true
} }