Skip to content

Commit 49f59f0

Browse files
committed
changed view helper
1 parent 85a106b commit 49f59f0

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

bootstrap/go.mod

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ require (
88
)
99

1010
require (
11+
github.com/anthdm/gothkit v0.0.0-20240608092625-85a106b8717c
1112
github.com/fatih/color v1.16.0 // indirect
1213
github.com/mattn/go-colorable v0.1.13 // indirect
1314
github.com/mattn/go-isatty v0.0.20 // indirect
1415
)
1516

1617
require (
1718
github.com/a-h/templ v0.2.707
18-
github.com/anthdm/gothkit v0.0.0-20240608091251-8198dfa775c8
1919
github.com/go-chi/chi/v5 v5.0.12
2020
github.com/jinzhu/inflection v1.0.0 // indirect
2121
github.com/joho/godotenv v1.5.1
@@ -26,3 +26,8 @@ require (
2626
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
2727
golang.org/x/sys v0.19.0 // indirect
2828
)
29+
30+
// Uncomment this if you are working directly on the core gothkit repo.
31+
// This will directly reflect changes you've made in the gothkit core repo
32+
// to the bootstrap folder.
33+
// replace github.com/anthdm/gothkit => ../

bootstrap/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ github.com/a-h/templ v0.2.707 h1:T1Gkd2ugbRglZ9rYw/VBchWOSZVKmetDbBkm4YubM7U=
22
github.com/a-h/templ v0.2.707/go.mod h1:5cqsugkq9IerRNucNsI4DEamdHPsoGMQy99DzydLhM8=
33
github.com/anthdm/gothkit v0.0.0-20240608091251-8198dfa775c8 h1:2C+WGVrNvIiSLFLJRRgKasJ8aWXR2pfsOh3T5flcMwI=
44
github.com/anthdm/gothkit v0.0.0-20240608091251-8198dfa775c8/go.mod h1:/zW/YMI9hOvRTQwmpfRU+CoJ+m4LZYuzC496KFOJAM8=
5+
github.com/anthdm/gothkit v0.0.0-20240608092625-85a106b8717c h1:JYV/co6zKfSR4eR/MVORi6wQvva1tikbBS8Xgd2GVFc=
6+
github.com/anthdm/gothkit v0.0.0-20240608092625-85a106b8717c/go.mod h1:/zW/YMI9hOvRTQwmpfRU+CoJ+m4LZYuzC496KFOJAM8=
57
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
68
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
79
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=

view/view.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@ import (
55
"fmt"
66
"net/url"
77

8-
"github.com/a-h/templ"
98
"github.com/anthdm/gothkit/kit"
109
"github.com/anthdm/gothkit/kit/middleware"
1110
)
1211

13-
func Asset(name string) templ.SafeURL {
14-
return templ.URL(fmt.Sprintf("/public/assets/%s", name))
12+
// Asset is view helper that returns the full asset path as a
13+
// string based on the given asset name.
14+
//
15+
// view.Asset("styles.css") // => /public/assets/styles.css.
16+
func Asset(name string) string {
17+
return fmt.Sprintf("/public/assets/%s", name)
1518
}
1619

1720
// Auth is a view helper function that returns the current Auth.
1821
// If Auth is not set a default auth will be returned
22+
//
23+
// view.Auth(ctx)
1924
func Auth(ctx context.Context) kit.Auth {
2025
value, ok := ctx.Value(kit.AuthKey{}).(kit.Auth)
2126
if !ok {
@@ -26,7 +31,8 @@ func Auth(ctx context.Context) kit.Auth {
2631

2732
// URL is a view helper that returns the current URL.
2833
// The request path can be acccessed with:
29-
// view.URL(ctx).Path
34+
//
35+
// view.URL(ctx).Path // => ex. /login
3036
func URL(ctx context.Context) *url.URL {
3137
value, ok := ctx.Value(middleware.RequestURLKey{}).(*url.URL)
3238
if !ok {

0 commit comments

Comments
 (0)