You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54-29
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,18 @@
1
1
# GoSvelt
2
-
the`fasthttp``fullstack` golang framwork using `svelte` (support tailwindcss).
3
-
just more 10 time faster than `sveltekit`
2
+
The`fasthttp``fullstack` golang framwork using `svelte` (support tailwindcss)
3
+
that use to be (blazingly) faster than default`sveltekit`
4
4
5
-
## why gosvelt ?
6
-
### fullstack integration of svelte
7
-
yeah, gosvelt will compile, group, and serve svelte pages.
8
-
A Svelte or AdvancedSvelte handler will give you a **svelte map** wich contain "js" and "css" URLs and you can add to this map your own attributes that will be rendered on the html template (note: if you add for example a "test" element to the map, you have to add the `&{test}` element in the html template)
5
+
## Why GoSvelt ?
6
+
### Fullstack integration of Svelte
7
+
Yeah, gosvelt will compile, group, and serve svelte pages at runtime which is pretty cool.
8
+
We are using the vitejs/vite svelte typescript compiler, with this, we can do likely everything we want, we could add few really interesting options.
9
+
The "compiler" accept for the moment javascript / typescript svelte and tailwindcss, if you want some features to be added, i'll be happy to add them.
10
+
A Svelte handler will give you a **svelte map** wich contain "js" and "css" URLs, you can add to this map your own attributes that will be rendered on the html template (Note: if you add for example a "test" element to the map, you have to add the `&{test}` element in the html template)
9
11
```golang
10
12
funcmain() {
11
-
r:= gosvelt.New()
13
+
app:= gosvelt.New()
12
14
13
-
r.Svelte("/", "App.svelte",
15
+
app.Svelte("/", "App.svelte",
14
16
func(c *gs.Context, svelte gs.Map) error {
15
17
return c.Html(200, "assets/index.html", svelte)
16
18
},
@@ -19,62 +21,85 @@ func main() {
19
21
gs.WithRoot("views"),
20
22
)
21
23
22
-
r.Start(":80")
24
+
app.Start(":80")
23
25
}
24
26
```
25
-
### cool way to made sse
26
-
there are actyally two way to use sse in gosvelt: the **context** way wich is in a context and can use channels declared in the handler. And the **handler** way wich is an handler function and use channels who are declared outside the handler.
27
+
You can note that this could be faster (blazingly fast) than default sveltekit or default vite server as go is likely way faster than nodejs.
28
+
### Cool way to do SSE
29
+
There are actually two way to use sse in gosvelt:
30
+
- The **context** way where you can instantiate your channels in the handler function and you can return a goroutine that will handle the sse stream.
31
+
- The **handler** way wich is a handler that will take outside channels (it could be really nice if you have some external struct for events handling) and instead of giving a handler function, you just give the goroutine function that will handle the sse stream.
27
32
```golang
28
33
funcmain() {
29
-
r:= gosvelt.New()
34
+
app:= gosvelt.New()
30
35
31
-
r.Get("/sse", func(c *gs.Context) error {// context way
36
+
app.Get("/sse", func(c *gs.Context) error {
32
37
datach:=make(chaninterface{})
33
38
closech:=make(chanstruct{})
34
39
35
40
return c.Sse(datach, closech, func() {
36
-
datach <-"hello"
41
+
deferclose(closech)
42
+
datach <-"hello world"
37
43
38
-
fori:=0; i < 10; i++ {
39
-
time.Sleep(100 * time.Millisecond)
40
-
datach <- fmt.Sprintf("%d -> actual time is %v", i, time.Now())
44
+
fori:=0; i < 6; i++ {
45
+
time.Sleep(200 * time.Millisecond)
46
+
datach <- gs.SseEvent{
47
+
Name: "date",
48
+
Data: fmt.Sprintf("time: %v", time.Now()),
49
+
}
41
50
}
42
-
43
-
close(closech)
44
51
})
45
52
})
46
53
47
-
r.Start(":80")
54
+
datach:=make(chaninterface{})
55
+
closech:=make(chanstruct{})
56
+
57
+
app.Sse("/ssetoo", datach, closech, func() {
58
+
deferclose(closech)
59
+
datach <-"hello world"
60
+
61
+
fori:=0; i < 6; i++ {
62
+
time.Sleep(200 * time.Millisecond)
63
+
datach <- gs.SseEvent{
64
+
Name: "date",
65
+
Data: fmt.Sprintf("time: %v", time.Now()),
66
+
}
67
+
}
68
+
})
69
+
70
+
app.Start(":80")
48
71
}
49
72
```
50
-
### pretty simple syntax
51
-
the syntax is like popular framworks like fiber, gin, echo
73
+
### Pretty simple syntax
74
+
The syntax is really easy to remember / use if you are beggining with golang framworks and if you already know all this (useless) framworking stuff, it's like most popular framworks (fiber, gin, echo, ...) so you won't be lost!
0 commit comments