-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c869eab
commit e30e567
Showing
13 changed files
with
253 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,7 @@ | |
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
data/ | ||
|
||
config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package html | ||
|
||
import ( | ||
"embed" | ||
"html/template" | ||
"io" | ||
"net/http" | ||
|
||
"github.com/Ordspilleren/ChangeMonitor/monitor" | ||
) | ||
|
||
//go:embed *.html | ||
var htmlTemplates embed.FS | ||
|
||
//go:embed assets | ||
var assets embed.FS | ||
|
||
var ( | ||
monitorList = parse("monitorlist.html") | ||
) | ||
|
||
type MonitorListParams struct { | ||
Monitors *monitor.Monitors | ||
} | ||
|
||
func MonitorList(w io.Writer, p MonitorListParams) error { | ||
return monitorList.Execute(w, p) | ||
} | ||
|
||
func parse(file string) *template.Template { | ||
return template.Must( | ||
template.New("layout.html").ParseFS(htmlTemplates, "layout.html", file)) | ||
} | ||
|
||
func GetAssetFS() http.FileSystem { | ||
return http.FS(assets) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Change Monitor</title> | ||
<link rel="stylesheet" href="assets/bulma.min.css"> | ||
</head> | ||
|
||
<body> | ||
<section class="section"> | ||
<div class="container"> | ||
<div class="columns is-centered"> | ||
<div class="column is-half"> | ||
<h1 class="title"> | ||
Change Monitor | ||
</h1> | ||
|
||
{{block "content" .}}{{end}} | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{{define "content"}} | ||
<table class="table is-striped"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>URL</th> | ||
<th>Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{{range .Monitors}} | ||
<tr> | ||
<td>{{.Name}}</td> | ||
<td><a | ||
href="{{.URL}}">{{.URL}}</a> | ||
</td> | ||
<td> | ||
<div class="buttons"> | ||
<button class="button is-small is-primary">Primary</button> | ||
<button class="button is-small is-danger">Link</button> | ||
</div> | ||
</td> | ||
</tr> | ||
{{end}} | ||
</tbody> | ||
</table> | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package notify | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
type Notifier interface { | ||
Init() | ||
Send(context.Context, string, string) error | ||
} | ||
|
||
type NotifierList []Notifier | ||
|
||
type NotifierMap map[string]Notifier | ||
|
||
type Notifiers struct { | ||
Mailgun *Mailgun `json:"mailgun"` | ||
Telegram *Telegram `json:"telegram"` | ||
} | ||
|
||
type Mailgun struct { | ||
Domain string `json:"domain"` | ||
ApiKey string `json:"apiKey"` | ||
SenderAddress string `json:"senderAddress"` | ||
WithEurope bool `json:"withEurope"` | ||
Receivers []string `json:"receivers"` | ||
} | ||
|
||
func (n *Notifiers) InitNotifiers() NotifierMap { | ||
notifiers := make(NotifierMap) | ||
|
||
if n.Telegram != nil { | ||
n.Telegram.Init() | ||
notifiers["telegram"] = n.Telegram | ||
} | ||
|
||
return notifiers | ||
} | ||
|
||
func (n NotifierList) Send(ctx context.Context, subject, message string) error { | ||
var eg errgroup.Group | ||
|
||
for _, service := range n { | ||
if service != nil { | ||
s := service | ||
eg.Go(func() error { | ||
return s.Send(ctx, subject, message) | ||
}) | ||
} | ||
} | ||
|
||
err := eg.Wait() | ||
if err != nil { | ||
err = errors.Wrap(err, err.Error()) | ||
} | ||
|
||
return err | ||
} |
Oops, something went wrong.