ran staticcheck and fixed warnings
This commit is contained in:
parent
741095822a
commit
f2b9e4a3ea
6 changed files with 20 additions and 49 deletions
4
main.go
4
main.go
|
@ -26,8 +26,6 @@ import (
|
|||
"gorm.io/gorm"
|
||||
|
||||
"broodjeaap.net/go-watch/notifiers"
|
||||
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
//go:embed templates static watchTemplates config.tmpl
|
||||
|
@ -497,7 +495,7 @@ func (web *Web) watchView(c *gin.Context) {
|
|||
|
||||
colorMap := make(map[string]int, len(names))
|
||||
index := 0
|
||||
for name, _ := range names {
|
||||
for name := range names {
|
||||
colorMap[name] = index % 16 // only 16 colors
|
||||
index += 1
|
||||
}
|
||||
|
|
|
@ -30,10 +30,6 @@ type Filter struct {
|
|||
Logs []string `gorm:"-:all"`
|
||||
}
|
||||
|
||||
func (filter *Filter) logf(format string, v ...any) {
|
||||
filter.Logs = append(filter.Logs, html.EscapeString(fmt.Sprintf(format, v...)))
|
||||
}
|
||||
|
||||
func (filter *Filter) log(v ...any) {
|
||||
filter.Logs = append(filter.Logs, html.EscapeString(fmt.Sprint(v...)))
|
||||
}
|
||||
|
|
27
scraping.go
27
scraping.go
|
@ -412,9 +412,7 @@ func getFilterResultMatch(filter *Filter) {
|
|||
}
|
||||
for _, parent := range filter.Parents {
|
||||
for _, result := range parent.Results {
|
||||
for _, str := range r.FindAllString(result, -1) {
|
||||
filter.Results = append(filter.Results, str)
|
||||
}
|
||||
filter.Results = append(filter.Results, r.FindAllString(result, -1)...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -702,16 +700,14 @@ func getFilterResultConditionLowest(filter *Filter, db *gorm.DB) {
|
|||
var previousOutputs []FilterOutput
|
||||
db.Model(&FilterOutput{}).Where("watch_id = ? AND name = ?", filter.WatchID, filter.Name).Find(&previousOutputs)
|
||||
lowest := math.MaxFloat64
|
||||
if previousOutputs != nil {
|
||||
for _, previousOutput := range previousOutputs {
|
||||
number, err := strconv.ParseFloat(previousOutput.Value, 64)
|
||||
if err != nil {
|
||||
filter.log("Could not convert result to number: '", previousOutput.Value, "'")
|
||||
continue
|
||||
}
|
||||
if number < lowest {
|
||||
lowest = number
|
||||
}
|
||||
for _, previousOutput := range previousOutputs {
|
||||
number, err := strconv.ParseFloat(previousOutput.Value, 64)
|
||||
if err != nil {
|
||||
filter.log("Could not convert result to number: '", previousOutput.Value, "'")
|
||||
continue
|
||||
}
|
||||
if number < lowest {
|
||||
lowest = number
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -856,8 +852,7 @@ func getFilterResultConditionHigherThan(filter *Filter) {
|
|||
}
|
||||
|
||||
func getFilterResultUnique(filter *Filter) {
|
||||
var valueMap map[string]bool
|
||||
valueMap = make(map[string]bool)
|
||||
valueMap := make(map[string]bool)
|
||||
|
||||
for _, parent := range filter.Parents {
|
||||
for _, result := range parent.Results {
|
||||
|
@ -865,7 +860,7 @@ func getFilterResultUnique(filter *Filter) {
|
|||
}
|
||||
}
|
||||
|
||||
for value, _ := range valueMap {
|
||||
for value := range valueMap {
|
||||
filter.Results = append(filter.Results, value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ func TestFilterXPath(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, test := range tests {
|
||||
testname := fmt.Sprintf("%s", test.Query)
|
||||
testname := test.Query
|
||||
t.Run(testname, func(t *testing.T) {
|
||||
filter := Filter{
|
||||
Parents: []*Filter{
|
||||
|
@ -89,7 +89,7 @@ func TestFilterJSON(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, test := range tests {
|
||||
testname := fmt.Sprintf("%s", test.Query)
|
||||
testname := test.Query
|
||||
t.Run(testname, func(t *testing.T) {
|
||||
filter := Filter{
|
||||
Parents: []*Filter{
|
||||
|
@ -120,7 +120,7 @@ func TestFilterCSS(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, test := range tests {
|
||||
testname := fmt.Sprintf("%s", test.Query)
|
||||
testname := test.Query
|
||||
t.Run(testname, func(t *testing.T) {
|
||||
filter := Filter{
|
||||
Parents: []*Filter{
|
||||
|
@ -208,7 +208,7 @@ func TestFilterMatch(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, test := range tests {
|
||||
testname := fmt.Sprintf("%s", test.Query)
|
||||
testname := test.Query
|
||||
t.Run(testname, func(t *testing.T) {
|
||||
filter := Filter{
|
||||
Parents: []*Filter{
|
||||
|
@ -1170,13 +1170,11 @@ func TestFilterUnique(t *testing.T) {
|
|||
getFilterResultUnique(
|
||||
&filter,
|
||||
)
|
||||
var wantMap map[string]bool
|
||||
wantMap = make(map[string]bool)
|
||||
wantMap := make(map[string]bool)
|
||||
for _, want := range test.Want {
|
||||
wantMap[want] = true
|
||||
}
|
||||
var resultMap map[string]bool
|
||||
resultMap = make(map[string]bool)
|
||||
resultMap := make(map[string]bool)
|
||||
for _, result := range filter.Results {
|
||||
resultMap[result] = true
|
||||
}
|
||||
|
@ -1211,7 +1209,7 @@ end`
|
|||
}
|
||||
|
||||
for _, test := range tests {
|
||||
testname := fmt.Sprintf("%s", test.Name)
|
||||
testname := test.Name
|
||||
t.Run(testname, func(t *testing.T) {
|
||||
filter := Filter{
|
||||
Var1: test.Lua,
|
||||
|
@ -1256,7 +1254,7 @@ if not(result==true) then error("regexp.match()") end`
|
|||
}
|
||||
|
||||
for _, test := range tests {
|
||||
testname := fmt.Sprintf("%s", test.Name)
|
||||
testname := test.Name
|
||||
t.Run(testname, func(t *testing.T) {
|
||||
filter := Filter{
|
||||
Parents: []*Filter{
|
||||
|
|
1
todo.md
1
todo.md
|
@ -1,6 +1,5 @@
|
|||
# Todo
|
||||
- comments
|
||||
- run/fix staticcheck
|
||||
- add compose templates for:
|
||||
- sqlite
|
||||
- sqlite+apprise
|
||||
|
|
15
util.go
15
util.go
|
@ -12,21 +12,6 @@ func bindAndValidateWatch(watch *Watch, c *gin.Context) (map[string]string, erro
|
|||
return validate(err), err
|
||||
}
|
||||
|
||||
func bindAndValidateFilter(filter *Filter, c *gin.Context) (map[string]string, error) {
|
||||
err := c.ShouldBind(filter)
|
||||
return validate(err), err
|
||||
}
|
||||
|
||||
func bindAndValidateGroupUpdate(group *FilterGroupUpdate, c *gin.Context) (map[string]string, error) {
|
||||
err := c.ShouldBind(group)
|
||||
return validate(err), err
|
||||
}
|
||||
|
||||
func bindAndValidateFilterUpdate(filter *FilterUpdate, c *gin.Context) (map[string]string, error) {
|
||||
err := c.ShouldBind(filter)
|
||||
return validate(err), err
|
||||
}
|
||||
|
||||
func prettyError(fieldError validator.FieldError) string {
|
||||
switch fieldError.Tag() {
|
||||
case "required":
|
||||
|
|
Loading…
Add table
Reference in a new issue