workin
parent
6b32728591
commit
a901e41d25
|
|
@ -0,0 +1,23 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"local/args"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
as := args.NewArgSet()
|
||||||
|
as.Append(args.INT, "p", "port to listen on", "8101")
|
||||||
|
as.Append(args.STRING, "f", "file to abuse", "/tmp/ledger-ui.dat")
|
||||||
|
if err := as.Parse(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
ledger, err := NewLedger(as.GetString("f"))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if err := http.ListenAndServe(":"+fmt.Sprint(as.GetInt("p")), Server{ledger: ledger}); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -21,11 +21,11 @@
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
function init() {
|
function init() {
|
||||||
http("get", "/ledger.json", (body, status) => {
|
http("get", "/api/transactions", (body, status) => {
|
||||||
body = JSON.parse(body)
|
body = JSON.parse(body)
|
||||||
loadTransactions(body.Transactions)
|
loadTransactions(body.Transactions)
|
||||||
}, null)
|
}, null)
|
||||||
http("get", "/balances.json", (body, status) => {
|
http("get", "/api/balances", (body, status) => {
|
||||||
body = JSON.parse(body)
|
body = JSON.parse(body)
|
||||||
loadBalances(body.Balances)
|
loadBalances(body.Balances)
|
||||||
}, null)
|
}, null)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "embed"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed public/index.html
|
||||||
|
var index string
|
||||||
|
|
||||||
|
type Server struct {
|
||||||
|
ledger Ledger
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
log.Println(r.Method + r.URL.Path)
|
||||||
|
switch r.Method + r.URL.Path {
|
||||||
|
case "GET/api/transactions":
|
||||||
|
server.getTransactions(w, r)
|
||||||
|
case "PUT/api/transactions":
|
||||||
|
server.putTransactions(w, r)
|
||||||
|
case "GET/api/balances":
|
||||||
|
server.getBalances(w, r)
|
||||||
|
default:
|
||||||
|
fmt.Fprint(w, index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server Server) getTransactions(w http.ResponseWriter, r *http.Request) {
|
||||||
|
transactions, err := server.ledger.Transactions()
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server Server) putTransactions(w http.ResponseWriter, r *http.Request) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server Server) getBalances(w http.ResponseWriter, r *http.Request) {
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue