added flag for port
This commit is contained in:
parent
03c7678499
commit
1d820b5590
2 changed files with 22 additions and 3 deletions
10
main.go
10
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))
|
||||
|
|
15
run.sh
15
run.sh
|
@ -1,3 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Default values
|
||||
PORT=8080
|
||||
|
||||
go run discord.go rss.go telegram.go main.go
|
||||
# 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
|
||||
|
|
Loading…
Reference in a new issue