From 1d820b5590bc9281a44cb2750cc3d77edfd8ae33 Mon Sep 17 00:00:00 2001 From: partisan Date: Wed, 14 Aug 2024 14:18:58 +0200 Subject: [PATCH] added flag for port --- main.go | 10 ++++++++-- run.sh | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 4271655..0505633 100644 --- a/main.go +++ b/main.go @@ -63,13 +63,16 @@ func init() { } func main() { + // Parse the flags flag.Parse() + // Retrieve the Telegram bot token from the environment variable botToken := os.Getenv("TELEGRAM_BOT_TOKEN") if botToken == "" { botToken = botTokenEnv } + // Initialize the Telegram bot var err error bot, err = tgbotapi.NewBotAPI(botToken) if err != nil { @@ -78,17 +81,19 @@ func main() { go startTelegramBot() } + // Retrieve blog entries from the data directory blogs, err = getBlogs(dataDir) if err != nil { log.Fatalf("Error getting blogs: %v", err) } + // Start watching for changes in the data directory go watchForChanges(dataDir) - // Serve static files (CSS, JS, etc.) from the /assets directory + // Serve static files (CSS, JS, etc.) from the /static directory http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir)))) - // Route Handlers + // Define route handlers http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/" { renderIndex(w) @@ -147,6 +152,7 @@ func main() { http.NotFound(w, r) }) + // Start the HTTP server on the specified port serverURL := fmt.Sprintf("http://localhost:%d", port) log.Printf("Starting server on %s", serverURL) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil)) diff --git a/run.sh b/run.sh index fd938e4..d26f4e9 100755 --- a/run.sh +++ b/run.sh @@ -1,3 +1,16 @@ +#!/bin/bash +# Default values +PORT=8080 -go run discord.go rss.go telegram.go main.go \ No newline at end of file +# Parse command-line arguments +while [[ "$#" -gt 0 ]]; do + case $1 in + -p|--port) PORT="$2"; shift ;; + *) echo "Unknown parameter passed: $1"; exit 1 ;; + esac + shift +done + +# Run the Go application with the parsed flags +go run discord.go rss.go telegram.go main.go -p=$PORT