Init commit: success to render tx
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.env
|
||||||
14
index.html
Normal file
14
index.html
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Ledger Quick Note</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Ledger Quick Note</h1>
|
||||||
|
<form action="/action" method="POST">
|
||||||
|
<label>Action: <input name="action" type="text"></label>
|
||||||
|
<label>Amount: <input name="amount" type="number"></label>
|
||||||
|
<input type="submit">
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
56
main.go
Normal file
56
main.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"text/template"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var tpl *template.Template
|
||||||
|
|
||||||
|
type TxData struct {
|
||||||
|
Date string
|
||||||
|
Amount string
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
var err error
|
||||||
|
tpl, err = template.ParseGlob("templates/*.txt")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
log.Println(tpl.DefinedTemplates())
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("Hi")
|
||||||
|
|
||||||
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.ServeFile(w, r, "index.html")
|
||||||
|
})
|
||||||
|
|
||||||
|
http.HandleFunc("/action", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if err := r.ParseForm(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Println(r.Form)
|
||||||
|
if err := renderTx(w, r.Form); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Fatal(http.ListenAndServe(":8000", nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
func renderTx(w io.Writer, params url.Values) (err error) {
|
||||||
|
name := params.Get("action")
|
||||||
|
data := TxData{
|
||||||
|
Date: time.Now().Format("2006/01/02"),
|
||||||
|
Amount: params.Get("amount"),
|
||||||
|
}
|
||||||
|
return tpl.ExecuteTemplate(w, name, data)
|
||||||
|
}
|
||||||
4
templates/cash.txt
Normal file
4
templates/cash.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{{ .Date }} * cash
|
||||||
|
cash ${{ .Amount }}
|
||||||
|
assets:cash
|
||||||
|
|
||||||
4
templates/withdraw.txt
Normal file
4
templates/withdraw.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{{ .Date }} * withdraw
|
||||||
|
assets:cash ${{ .Amount }}
|
||||||
|
assets:checking
|
||||||
|
|
||||||
Reference in New Issue
Block a user