mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-12-26 23:42:29 -05:00
Move Report and Series definitions to be in line with others
This commit is contained in:
parent
9b3e08fa78
commit
5d583a2315
22
reports.go
22
reports.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/yuin/gopher-lua"
|
"github.com/yuin/gopher-lua"
|
||||||
"log"
|
"log"
|
||||||
@ -23,6 +24,26 @@ const (
|
|||||||
|
|
||||||
const luaTimeoutSeconds time.Duration = 5 // maximum time a lua request can run for
|
const luaTimeoutSeconds time.Duration = 5 // maximum time a lua request can run for
|
||||||
|
|
||||||
|
type Series struct {
|
||||||
|
Values []float64
|
||||||
|
Children map[string]*Series
|
||||||
|
}
|
||||||
|
|
||||||
|
type Report struct {
|
||||||
|
ReportId string
|
||||||
|
Title string
|
||||||
|
Subtitle string
|
||||||
|
XAxisLabel string
|
||||||
|
YAxisLabel string
|
||||||
|
Labels []string
|
||||||
|
Series map[string]*Series
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Report) Write(w http.ResponseWriter) error {
|
||||||
|
enc := json.NewEncoder(w)
|
||||||
|
return enc.Encode(r)
|
||||||
|
}
|
||||||
|
|
||||||
func runReport(user *User, reportpath string) (*Report, error) {
|
func runReport(user *User, reportpath string) (*Report, error) {
|
||||||
// Create a new LState without opening the default libs for security
|
// Create a new LState without opening the default libs for security
|
||||||
L := lua.NewState(lua.Options{SkipOpenLibs: true})
|
L := lua.NewState(lua.Options{SkipOpenLibs: true})
|
||||||
@ -113,6 +134,7 @@ func ReportHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Print(err)
|
log.Print(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
report.ReportId = reportname
|
||||||
|
|
||||||
err = report.Write(w)
|
err = report.Write(w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,33 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"github.com/yuin/gopher-lua"
|
"github.com/yuin/gopher-lua"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const luaReportTypeName = "report"
|
const luaReportTypeName = "report"
|
||||||
const luaSeriesTypeName = "series"
|
const luaSeriesTypeName = "series"
|
||||||
|
|
||||||
type Series struct {
|
|
||||||
Values []float64
|
|
||||||
Children map[string]*Series
|
|
||||||
}
|
|
||||||
|
|
||||||
type Report struct {
|
|
||||||
Title string
|
|
||||||
Subtitle string
|
|
||||||
XAxisLabel string
|
|
||||||
YAxisLabel string
|
|
||||||
Labels []string
|
|
||||||
Series map[string]*Series
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Report) Write(w http.ResponseWriter) error {
|
|
||||||
enc := json.NewEncoder(w)
|
|
||||||
return enc.Encode(r)
|
|
||||||
}
|
|
||||||
|
|
||||||
func luaRegisterReports(L *lua.LState) {
|
func luaRegisterReports(L *lua.LState) {
|
||||||
mtr := L.NewTypeMetatable(luaReportTypeName)
|
mtr := L.NewTypeMetatable(luaReportTypeName)
|
||||||
L.SetGlobal("report", mtr)
|
L.SetGlobal("report", mtr)
|
||||||
|
Loading…
Reference in New Issue
Block a user