From 6e3c4bf647461fe33f4b434057f71bdf83e64904 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Sat, 30 Mar 2024 09:55:37 +0100 Subject: [PATCH] Added ability to specify port and RSS file as command line arguments --- cmd/control/cli.go | 14 +++++++++++++- cmd/main.go | 2 +- cmd/view/articles.go | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/control/cli.go b/cmd/control/cli.go index 1d04997..d880798 100644 --- a/cmd/control/cli.go +++ b/cmd/control/cli.go @@ -10,7 +10,9 @@ type CliArgs struct { DBName string KeyFile string LogFile string + Port string PicsDir string + RSSFile string WebDir string } @@ -18,9 +20,11 @@ func HandleCliArgs() (*CliArgs, error) { var err error cliArgs := new(CliArgs) - keyFile := flag.String("key", "/var/www/cpolis.key", "key file") + keyFile := flag.String("key", "/var/www/cpolis/cpolis.key", "key file") logFile := flag.String("log", "/var/log/cpolis.log", "log file") picsDir := flag.String("pics", "/var/www/cpolis/pics", "pictures directory") + cliArgs.Port = fmt.Sprint(":", flag.Int("port", 8080, "port")) + rssFile := flag.String("rss", "/var/www/cpolis/cpolis.rss", "RSS file") webDir := flag.String("web", "/var/www/cpolis/web", "web directory") flag.StringVar(&cliArgs.DBName, "db", "cpolis", "DB name") flag.Parse() @@ -29,14 +33,22 @@ func HandleCliArgs() (*CliArgs, error) { if err != nil { return nil, fmt.Errorf("error finding absolute path for KeyFile: %v", err) } + cliArgs.LogFile, err = filepath.Abs(*logFile) if err != nil { return nil, fmt.Errorf("error finding absolute path for LogFile: %v", err) } + cliArgs.PicsDir, err = filepath.Abs(*picsDir) if err != nil { return nil, fmt.Errorf("error finding absolute path for PicsDir: %v", err) } + + cliArgs.RSSFile, err = filepath.Abs(*rssFile) + if err != nil { + return nil, fmt.Errorf("error finding absolute path for RSSFile: %v", err) + } + cliArgs.WebDir, err = filepath.Abs(*webDir) if err != nil { return nil, fmt.Errorf("error finding absolute path for WebDir: %v", err) diff --git a/cmd/main.go b/cmd/main.go index 2f33d62..8aed844 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -78,5 +78,5 @@ func main() { mux.HandleFunc("POST /update-user/", view.UpdateUser(args, db, store)) mux.HandleFunc("POST /upload-image/", view.UploadImage(args)) - log.Fatalln(http.ListenAndServe(":8080", mux)) + log.Fatalln(http.ListenAndServe(args.Port, mux)) } diff --git a/cmd/view/articles.go b/cmd/view/articles.go index f28d1c8..ac13cca 100644 --- a/cmd/view/articles.go +++ b/cmd/view/articles.go @@ -319,7 +319,7 @@ func PublishArticle(c *control.CliArgs, db *model.DB, s *control.CookieStore) ht http.Error(w, err.Error(), http.StatusInternalServerError) return } - if err = control.SaveRSS("tmp/orientexpress_alle.rss", feed); err != nil { + if err = control.SaveRSS(c.RSSFile, feed); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return