added flags for writing template config to file or stdout

This commit is contained in:
BroodjeAap 2022-12-30 12:26:01 +00:00
parent f9a9a87a31
commit 58539471cd
3 changed files with 66 additions and 3 deletions

37
config.tmpl Normal file
View file

@ -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://<bot_token>/<chat_id>/"
- "discord://<WebhookID>/<WebhookToken>/"
Shoutrrr: # See: https://containrrr.dev/shoutrrr/v0.5/services/overview/
type: "shoutrrr"
urls:
- "telegram://<token>@telegram?chats=<channel-1-id>,<chat-2-id>"
Telegram:
token: "<token>" # See: https://core.telegram.org/bots#how-do-i-create-a-bot
chat: "<chatID>" # See: https://www.alphr.com/find-chat-id-telegram/
debug: false
Discord:
type: "discord"
token: "<token>" # See: https://www.writebots.com/discord-bot-token/
userID: "<userID>" # See: https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-
server:
ID: "<serverID>"
channel: "<channelID>"
debug: false
Email:
type: "email"
server: "smtp.relay.com"
port: "465"
from: "from@email.com"
user: "<user>"
password: "<password>"
to: "to@email.com"
database:
dsn: "./watch.db"
prune: "@every 1h"

29
main.go
View file

@ -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(".")

View file

@ -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
- try to make docker image smaller