~repos /gromer
git clone https://pyrossh.dev/repos/gromer.git
gromer is a framework and cli to build multipage web apps in golang using htmx and alpinejs.
addd context funcs
http.go
CHANGED
|
@@ -8,6 +8,7 @@ import (
|
|
|
8
8
|
"html/template"
|
|
9
9
|
"net"
|
|
10
10
|
"net/http"
|
|
11
|
+
"net/url"
|
|
11
12
|
"os"
|
|
12
13
|
"reflect"
|
|
13
14
|
"regexp"
|
|
@@ -58,13 +59,13 @@ type RouteDefinition struct {
|
|
|
58
59
|
Params interface{} `json:"params"`
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
func
|
|
62
|
+
func getFunctionName(temp interface{}) string {
|
|
62
63
|
strs := strings.Split((runtime.FuncForPC(reflect.ValueOf(temp).Pointer()).Name()), ".")
|
|
63
64
|
return strs[len(strs)-1]
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
func RegisterComponent(fn any, props ...string) {
|
|
67
|
-
name :=
|
|
68
|
+
name := getFunctionName(fn)
|
|
68
69
|
fnType := reflect.TypeOf(fn)
|
|
69
70
|
fnValue := reflect.ValueOf(fn)
|
|
70
71
|
handlebars.GlobalHelpers.Add(name, func(help handlebars.HelperContext) (template.HTML, error) {
|
|
@@ -385,3 +386,11 @@ func Handle(router *mux.Router, method, route string, h interface{}) {
|
|
|
385
386
|
func Styles(c context.Context) (handlebars.CssContent, int, error) {
|
|
386
387
|
return handlebars.GetStyles(), 200, nil
|
|
387
388
|
}
|
|
389
|
+
|
|
390
|
+
func GetUrl(ctx context.Context) *url.URL {
|
|
391
|
+
return ctx.Value("url").(*url.URL)
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
func GetHeader(ctx context.Context) http.Header {
|
|
395
|
+
return ctx.Value("header").(http.Header)
|
|
396
|
+
}
|