mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 18:31:24 +02:00
Update custom API
This commit is contained in:
parent
d400b27545
commit
61fd5481cc
@ -100,7 +100,7 @@ func fetchAndParseCustomAPI(req *http.Request, tmpl *template.Template) (templat
|
|||||||
|
|
||||||
var templateBuffer bytes.Buffer
|
var templateBuffer bytes.Buffer
|
||||||
|
|
||||||
data := CustomAPITemplateData{
|
data := customAPITemplateData{
|
||||||
JSON: decoratedGJSONResult{gjson.Parse(body)},
|
JSON: decoratedGJSONResult{gjson.Parse(body)},
|
||||||
Response: resp,
|
Response: resp,
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ type decoratedGJSONResult struct {
|
|||||||
gjson.Result
|
gjson.Result
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomAPITemplateData struct {
|
type customAPITemplateData struct {
|
||||||
JSON decoratedGJSONResult
|
JSON decoratedGJSONResult
|
||||||
Response *http.Response
|
Response *http.Response
|
||||||
}
|
}
|
||||||
@ -180,28 +180,28 @@ var customAPITemplateFuncs = func() template.FuncMap {
|
|||||||
"toInt": func(a float64) int64 {
|
"toInt": func(a float64) int64 {
|
||||||
return int64(a)
|
return int64(a)
|
||||||
},
|
},
|
||||||
"mathexpr": func(left float64, op string, right float64) float64 {
|
"add": func(a, b float64) float64 {
|
||||||
if right == 0 {
|
return a + b
|
||||||
|
},
|
||||||
|
"sub": func(a, b float64) float64 {
|
||||||
|
return a - b
|
||||||
|
},
|
||||||
|
"mul": func(a, b float64) float64 {
|
||||||
|
return a * b
|
||||||
|
},
|
||||||
|
"div": func(a, b float64) float64 {
|
||||||
|
if b == 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
switch op {
|
return a / b
|
||||||
case "+":
|
|
||||||
return left + right
|
|
||||||
case "-":
|
|
||||||
return left - right
|
|
||||||
case "*":
|
|
||||||
return left * right
|
|
||||||
case "/":
|
|
||||||
return left / right
|
|
||||||
default:
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value := range globalTemplateFunctions {
|
for key, value := range globalTemplateFunctions {
|
||||||
funcs[key] = value
|
if _, exists := funcs[key]; !exists {
|
||||||
|
funcs[key] = value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return funcs
|
return funcs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user