This repository was archived by the owner on Jul 14, 2023. It is now read-only.
File tree 4 files changed +26
-1
lines changed
4 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 1
1
< fragment src ="http://localhost:3000/fragment1 "> </ fragment >
2
2
< fragment src ="fragment2 " primary > </ fragment >
3
- < fragment src ="fragment3 " timeout ="10 " fallback ="fallback "> </ fragment >
3
+ < fragment src ="fragment3 " timeout ="1 " fallback ="fallback "> </ fragment >
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
10
10
11
11
"github.com/PuerkitoBio/goquery"
12
12
"github.com/gofiber/fiber/v2"
13
+ "github.com/google/uuid"
13
14
"github.com/valyala/fasthttp"
14
15
"golang.org/x/net/html"
15
16
)
@@ -24,6 +25,9 @@ type Fragment struct {
24
25
src string
25
26
timeout int64
26
27
28
+ id string
29
+ ref string
30
+
27
31
statusCode int
28
32
head []* html.Node
29
33
@@ -52,6 +56,15 @@ func FromSelection(s *goquery.Selection) *Fragment {
52
56
t , _ := strconv .ParseInt (timeout , 10 , 64 )
53
57
f .timeout = t
54
58
59
+ id , ok := s .Attr ("id" )
60
+ if ! ok {
61
+ id = uuid .New ().String ()
62
+ }
63
+ f .id = id
64
+
65
+ ref , _ := s .Attr ("ref" )
66
+ f .ref = ref
67
+
55
68
deferred , ok := s .Attr ("deferred" )
56
69
f .deferred = ok && strings .ToUpper (deferred ) != "FALSE"
57
70
@@ -105,6 +118,16 @@ func (f *Fragment) Links() []*html.Node {
105
118
return f .head
106
119
}
107
120
121
+ // Ref represents the reference to another fragment
122
+ func (f * Fragment ) Ref () string {
123
+ return f .ref
124
+ }
125
+
126
+ // ID represents a unique id for the fragment
127
+ func (f * Fragment ) ID () string {
128
+ return f .id
129
+ }
130
+
108
131
// Resolve is resolving all needed data, setting headers
109
132
// and the status code.
110
133
func (f * Fragment ) Resolve () ResolverFunc {
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ require (
6
6
github.com/PuerkitoBio/goquery v1.7.0
7
7
github.com/gofiber/fiber/v2 v2.13.0
8
8
github.com/gofiber/template v1.6.12
9
+ github.com/google/uuid v1.0.0
9
10
github.com/valyala/fasthttp v1.26.0
10
11
golang.org/x/net v0.0.0-20210510120150-4163338589ed
11
12
)
Original file line number Diff line number Diff line change @@ -129,6 +129,7 @@ github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXi
129
129
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57 /go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc =
130
130
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f /go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc =
131
131
github.com/google/renameio v0.1.0 /go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI =
132
+ github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA =
132
133
github.com/google/uuid v1.0.0 /go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo =
133
134
github.com/googleapis/gax-go/v2 v2.0.4 /go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg =
134
135
github.com/googleapis/gax-go/v2 v2.0.5 /go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk =
You can’t perform that action at this time.
0 commit comments