From 58539471cd8d7f37da7a870e54e4090d5fbc169c Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Fri, 30 Dec 2022 12:26:01 +0000 Subject: [PATCH] added flags for writing template config to file or stdout --- config.tmpl | 37 +++++++++++++++++++++++++++++++++++++ main.go | 29 ++++++++++++++++++++++++++++- todo.md | 3 +-- 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 config.tmpl diff --git a/config.tmpl b/config.tmpl new file mode 100644 index 0000000..7b59de5 --- /dev/null +++ b/config.tmpl @@ -0,0 +1,37 @@ +notifiers: + Apprise: # See: https://github.com/caronc/apprise-api#api-details + type: "apprise" + url: "http://apprise/notify" + title: "GoWatch notification through Apprise" + mtype: "info" # Note 'mtype' to avoid conflict with 'type' + format: "text" + urls: + - "tgram:////" + - "discord:////" + Shoutrrr: # See: https://containrrr.dev/shoutrrr/v0.5/services/overview/ + type: "shoutrrr" + urls: + - "telegram://@telegram?chats=," + Telegram: + token: "" # See: https://core.telegram.org/bots#how-do-i-create-a-bot + chat: "" # See: https://www.alphr.com/find-chat-id-telegram/ + debug: false + Discord: + type: "discord" + token: "" # See: https://www.writebots.com/discord-bot-token/ + userID: "" # See: https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID- + server: + ID: "" + channel: "" + debug: false + Email: + type: "email" + server: "smtp.relay.com" + port: "465" + from: "from@email.com" + user: "" + password: "" + to: "to@email.com" +database: + dsn: "./watch.db" + prune: "@every 1h" \ No newline at end of file diff --git a/main.go b/main.go index 06099fa..f23da46 100644 --- a/main.go +++ b/main.go @@ -3,12 +3,14 @@ package main import ( "embed" "encoding/json" + "flag" "fmt" "html/template" "io/fs" "io/ioutil" "log" "net/http" + "os" "strconv" "strings" @@ -27,7 +29,7 @@ import ( _ "embed" ) -//go:embed templates static watchTemplates +//go:embed templates static watchTemplates config.tmpl var EMBED_FS embed.FS type Web struct { @@ -700,6 +702,31 @@ func (web *Web) importWatch(c *gin.Context) { } func main() { + writeConfFlag := flag.String("writeConfig", "-", "Path to write template config to") + var printConfigFlag bool + flag.BoolVar(&printConfigFlag, "printConfig", false, "Print the template config to stdout") + flag.Parse() + + if *writeConfFlag != "-" { + conf, err := EMBED_FS.ReadFile("config.tmpl") + if err != nil { + log.Fatalln("Could not read config.tmpl") + } + os.WriteFile(*writeConfFlag, conf, 0666) + log.Println("Wrote template config to:", *writeConfFlag) + return + } + + if printConfigFlag { + conf, err := EMBED_FS.ReadFile("config.tmpl") + if err != nil { + log.Fatalln("Could not read config.tmpl") + } + log.SetFlags(0) + log.Println(string(conf)) + return + } + viper.SetConfigName("config") viper.SetConfigType("yaml") viper.AddConfigPath(".") diff --git a/todo.md b/todo.md index 937e1a8..8c1dcba 100644 --- a/todo.md +++ b/todo.md @@ -7,5 +7,4 @@ - add browserless support ? - file output notifier? - show startup warnings on page? -- try to make docker image smaller -- add config template output param \ No newline at end of file +- try to make docker image smaller \ No newline at end of file