mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 02:18:22 +02:00
Simplify implementation of func
This commit is contained in:
parent
32db59fda2
commit
bcef9fbd61
@ -414,14 +414,6 @@ func customAPIDoMathOp[T int | float64](a, b T, op string) T {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return a / b
|
return a / b
|
||||||
case "mod":
|
|
||||||
ai, bi := any(a), any(b)
|
|
||||||
aint, aok := ai.(int)
|
|
||||||
bint, bok := bi.(int)
|
|
||||||
if aok && bok && bint != 0 {
|
|
||||||
return T(aint % bint)
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -487,8 +479,11 @@ var customAPITemplateFuncs = func() template.FuncMap {
|
|||||||
"div": func(a, b any) any {
|
"div": func(a, b any) any {
|
||||||
return doMathOpWithAny(a, b, "div")
|
return doMathOpWithAny(a, b, "div")
|
||||||
},
|
},
|
||||||
"mod": func(a, b int) any {
|
"mod": func(a, b int) int {
|
||||||
return doMathOpWithAny(a, b, "mod")
|
if b == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return a % b
|
||||||
},
|
},
|
||||||
"now": func() time.Time {
|
"now": func() time.Time {
|
||||||
return time.Now()
|
return time.Now()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user