gziphttp
parent
747dc90e9b
commit
76f6cf1016
|
|
@ -4,11 +4,14 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gogs.inhome.blapointe.com/ana-ledger/ledger"
|
"gogs.inhome.blapointe.com/ana-ledger/ledger"
|
||||||
|
"gogs.inhome.blapointe.com/local/gziphttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -20,6 +23,7 @@ func main() {
|
||||||
groupName := flag.String("group-name", ".*", "grouping to apply to names")
|
groupName := flag.String("group-name", ".*", "grouping to apply to names")
|
||||||
groupDate := flag.String("group-date", ".*", "grouping to apply to dates")
|
groupDate := flag.String("group-date", ".*", "grouping to apply to dates")
|
||||||
jsonOutput := flag.Bool("json", false, "json output")
|
jsonOutput := flag.Bool("json", false, "json output")
|
||||||
|
httpOutput := flag.String("http", "", "http output listen address, like :8080")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if flag.NArg() < 1 {
|
if flag.NArg() < 1 {
|
||||||
|
|
@ -48,6 +52,39 @@ func main() {
|
||||||
like = append(like, ledger.LikeAfter(*likeAfter))
|
like = append(like, ledger.LikeAfter(*likeAfter))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *httpOutput != "" {
|
||||||
|
switch *foo {
|
||||||
|
case "reg":
|
||||||
|
foo := func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
register := deltas.Like(like...).Register()
|
||||||
|
|
||||||
|
nameCurrencyDateValue := map[string]map[ledger.Currency]map[string]float64{}
|
||||||
|
for date, balances := range register {
|
||||||
|
for name, balance := range balances {
|
||||||
|
for currency, value := range balance {
|
||||||
|
if _, ok := nameCurrencyDateValue[name]; !ok {
|
||||||
|
nameCurrencyDateValue[name] = make(map[ledger.Currency]map[string]float64)
|
||||||
|
}
|
||||||
|
if _, ok := nameCurrencyDateValue[name][currency]; !ok {
|
||||||
|
nameCurrencyDateValue[name][currency] = make(map[string]float64)
|
||||||
|
}
|
||||||
|
nameCurrencyDateValue[name][currency][date] += value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if gziphttp.Can(r) {
|
||||||
|
w = gziphttp.New(w)
|
||||||
|
}
|
||||||
|
json.NewEncoder(w).Encode(nameCurrencyDateValue)
|
||||||
|
}
|
||||||
|
log.Println("listening on", *httpOutput)
|
||||||
|
if err := http.ListenAndServe(*httpOutput, http.HandlerFunc(foo)); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
panic(fmt.Errorf("not impl %q", *foo))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
jsonResult := []any{}
|
jsonResult := []any{}
|
||||||
|
|
||||||
switch *foo {
|
switch *foo {
|
||||||
|
|
@ -88,10 +125,11 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("not impl %q", flag.Args()[0]))
|
panic(fmt.Errorf("not impl %q", *foo))
|
||||||
}
|
}
|
||||||
|
|
||||||
if *jsonOutput {
|
if *jsonOutput {
|
||||||
json.NewEncoder(os.Stdout).Encode(jsonResult)
|
json.NewEncoder(os.Stdout).Encode(jsonResult)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
5
go.mod
5
go.mod
|
|
@ -1,3 +1,8 @@
|
||||||
module gogs.inhome.blapointe.com/ana-ledger
|
module gogs.inhome.blapointe.com/ana-ledger
|
||||||
|
|
||||||
go 1.21.1
|
go 1.21.1
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/go-echarts/go-echarts/v2 v2.3.1 // indirect
|
||||||
|
gogs.inhome.blapointe.com/local/gziphttp v0.0.0-20230508014052-4ccd700640fc // indirect
|
||||||
|
)
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -0,0 +1,4 @@
|
||||||
|
github.com/go-echarts/go-echarts/v2 v2.3.1 h1:Yw0HVjVTxpYm48l974dMjRzx8ni2ql0kKi/kawSgxFE=
|
||||||
|
github.com/go-echarts/go-echarts/v2 v2.3.1/go.mod h1:56YlvzhW/a+du15f3S2qUGNDfKnFOeJSThBIrVFHDtI=
|
||||||
|
gogs.inhome.blapointe.com/local/gziphttp v0.0.0-20230508014052-4ccd700640fc h1:ayxolpOV9uIm8rGdmtz03d5JlnbSmFF8daKjmwrZZ1o=
|
||||||
|
gogs.inhome.blapointe.com/local/gziphttp v0.0.0-20230508014052-4ccd700640fc/go.mod h1:Sdj/NB9h3xrzPDqViQAHoDhA5gmpHkrWRXUauvLSA74=
|
||||||
Loading…
Reference in New Issue