-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
44 lines (33 loc) · 846 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"fmt"
"net/http"
"github.com/a-h/templ"
lua "msyavuz/peth/lua"
view "msyavuz/peth/views"
)
func main() {
index := view.Index()
http.Handle("/", templ.Handler(index))
http.HandleFunc("/lua", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "POST":
r.ParseForm()
// Get the pattern and test string from form data
pattern := r.FormValue("pattern")
testString := r.FormValue("test")
strArr := lua.Match(testString, pattern)
if len(strArr) == 0 {
listComponent := view.Error()
listComponent.Render(r.Context(), w)
} else {
listComponent := view.CapturedList(strArr)
listComponent.Render(r.Context(), w)
}
case "GET":
fmt.Fprint(w, "There is no get endpoint.")
}
})
fmt.Println("Listening on :3000")
http.ListenAndServe(":3000", nil)
}